sklearn.config_context

sklearn.config_context(*, assume_finite=None, working_memory=None, print_changed_only=None, display=None)[source]

Context manager for global scikit-learn configuration.

Parameters
assume_finitebool, default=None

If True, validation for finiteness will be skipped, saving time, but leading to potential crashes. If False, validation for finiteness will be performed, avoiding error. If None, the existing value won’t change. The default value is False.

working_memoryint, default=None

If set, scikit-learn will attempt to limit the size of temporary arrays to this number of MiB (per job when parallelised), often saving both computation time and memory on expensive operations that can be performed in chunks. If None, the existing value won’t change. The default value is 1024.

print_changed_onlybool, default=None

If True, only the parameters that were set to non-default values will be printed when printing an estimator. For example, print(SVC()) while True will only print ‘SVC()’, but would print ‘SVC(C=1.0, cache_size=200, …)’ with all the non-changed parameters when False. If None, the existing value won’t change. The default value is True.

Changed in version 0.23: Default changed from False to True.

display{‘text’, ‘diagram’}, default=None

If ‘diagram’, estimators will be displayed as a diagram in a Jupyter lab or notebook context. If ‘text’, estimators will be displayed as text. If None, the existing value won’t change. The default value is ‘text’.

New in version 0.23.

Yields
None.

See also

set_config

Set global scikit-learn configuration.

get_config

Retrieve current values of the global configuration.

Notes

All settings, not just those presently modified, will be returned to their previous values when the context manager is exited.

Examples

>>> import sklearn
>>> from sklearn.utils.validation import assert_all_finite
>>> with sklearn.config_context(assume_finite=True):
...     assert_all_finite([float('nan')])
>>> with sklearn.config_context(assume_finite=True):
...     with sklearn.config_context(assume_finite=False):
...         assert_all_finite([float('nan')])
Traceback (most recent call last):
...
ValueError: Input contains NaN...