config_context#
- sklearn.config_context(*,assume_finite=None,working_memory=None,print_changed_only=None,display=None,pairwise_dist_chunk_size=None,enable_cython_pairwise_dist=None,array_api_dispatch=None,transform_output=None,enable_metadata_routing=None,skip_parameter_validation=None)[source]#
Context manager to temporarily change the global scikit-learn configuration.
This context manager can be used to apply scikit-learn configuration changes withinthe scope of the with statement. Once the context exits, the global configuration isrestored again.
The default global configurations (which take effect when scikit-learn is imported)are defined below in the parameter list.
- Parameters:
- assume_finitebool, default=None
If True, validation for finiteness will be skipped,saving time, but leading to potential crashes. IfFalse, validation for finiteness will be performed,avoiding error. If None, the existing configuration won’t change.Global default: False.
- working_memoryint, default=None
If set, scikit-learn will attempt to limit the size of temporary arraysto this number of MiB (per job when parallelised), often saving bothcomputation time and memory on expensive operations that can beperformed in chunks. If None, the existing configuration won’t change.Global default: 1024.
- print_changed_onlybool, default=None
If True, only the parameters that were set to non-defaultvalues 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 parameterswhen False. If None, the existing configuration won’t change.Global default: True.Changed in version 0.23:Global default configuration changed from False to True.
- display{‘text’, ‘diagram’}, default=None
If ‘diagram’, estimators will be displayed as a diagram in a Jupyterlab or notebook context. If ‘text’, estimators will be displayed astext. If None, the existing configuration won’t change.Global default: ‘diagram’.
Added in version 0.23.
- pairwise_dist_chunk_sizeint, default=None
The number of row vectors per chunk for the accelerated pairwise-distances reduction backend. Global default: 256 (suitable for most ofmodern laptops’ caches and architectures).
Intended for easier benchmarking and testing of scikit-learn internals.End users are not expected to benefit from customizing this configurationsetting.
Added in version 1.1.
- enable_cython_pairwise_distbool, default=None
Use the accelerated pairwise-distances reduction backend whenpossible. Global default: True.
Intended for easier benchmarking and testing of scikit-learn internals.End users are not expected to benefit from customizing this configurationsetting.
Added in version 1.1.
- array_api_dispatchbool, default=None
Use Array API dispatching when inputs follow the Array API standard.Global default: False.
See theUser Guide for more details.
Added in version 1.2.
- transform_outputstr, default=None
Configure output of
transformandfit_transform.SeeIntroducing the set_output APIfor an example on how to use the API.
"default": Default output format of a transformer"pandas": DataFrame output"polars": Polars outputNone: Transform configuration is unchanged
Global default: “default”.
Added in version 1.2.
Added in version 1.4:
"polars"option was added.- enable_metadata_routingbool, default=None
Enable metadata routing. By default this feature is disabled.
Refer tometadata routing user guide for moredetails.
True: Metadata routing is enabledFalse: Metadata routing is disabled, use the old syntax.None: Configuration is unchanged
Global default: False.
Added in version 1.3.
- skip_parameter_validationbool, default=None
If
True, disable the validation of the hyper-parameters’ types and values inthe fit method of estimators and for arguments passed to public helperfunctions. It can save time in some situations but can lead to low levelcrashes and exceptions with confusing error messages.Global default: False.Note that for data parameters, such as
Xandy, only type validation isskipped but validation withcheck_arraywill continue to run.Added in version 1.3.
- Yields:
- None.
See also
set_configSet global scikit-learn configuration.
get_configRetrieve current values of the global configuration.
Notes
All settings, not just those presently modified, will be returned totheir previous values when the context manager is exited.
Examples
>>>importsklearn>>>fromsklearn.utils.validationimportassert_all_finite>>>withsklearn.config_context(assume_finite=True):...assert_all_finite([float('nan')])>>>withsklearn.config_context(assume_finite=True):...withsklearn.config_context(assume_finite=False):...assert_all_finite([float('nan')])Traceback (most recent call last):...ValueError:Input contains NaN...