Skip to content

Commit d0575ec

Browse files
DOC Improve docstrings for scikit-learn configuration functions (scikit-learn#31486)
Co-authored-by: Adrin Jalali <adrin.jalali@gmail.com>
1 parent 30816ac commit d0575ec

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

sklearn/_config.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def _get_threadlocal_config():
3333

3434

3535
def get_config():
36-
"""Retrieve current values for configuration set by :func:`set_config`.
36+
"""Retrieve the current scikit-learn configuration.
37+
38+
This reflects the effective global configurations as established by default upon
39+
library import, or modified via :func:`set_config` or :func:`config_context`.
3740
3841
Returns
3942
-------
@@ -71,6 +74,15 @@ def set_config(
7174
):
7275
"""Set global scikit-learn configuration.
7376
77+
These settings control the behaviour of scikit-learn functions during a library
78+
usage session. Global configuration defaults (as described in the parameter list
79+
below) take effect when scikit-learn is imported.
80+
81+
This function can be used to modify the global scikit-learn configuration at
82+
runtime. Passing `None` as an argument (the default) leaves the corresponding
83+
setting unchanged. This allows users to selectively update the global configuration
84+
values without affecting the others.
85+
7486
.. versionadded:: 0.19
7587
7688
Parameters
@@ -79,7 +91,7 @@ def set_config(
7991
If True, validation for finiteness will be skipped,
8092
saving time, but leading to potential crashes. If
8193
False, validation for finiteness will be performed,
82-
avoiding error. Global default: False.
94+
avoiding error. Global default: False.
8395
8496
.. versionadded:: 0.19
8597
@@ -96,20 +108,22 @@ def set_config(
96108
values will be printed when printing an estimator. For example,
97109
``print(SVC())`` while True will only print 'SVC()' while the default
98110
behaviour would be to print 'SVC(C=1.0, cache_size=200, ...)' with
99-
all the non-changed parameters.
111+
all the non-changed parameters. Global default: True.
100112
101113
.. versionadded:: 0.21
114+
.. versionchanged:: 0.23
115+
Global default configuration changed from False to True.
102116
103117
display : {'text', 'diagram'}, default=None
104118
If 'diagram', estimators will be displayed as a diagram in a Jupyter
105119
lab or notebook context. If 'text', estimators will be displayed as
106-
text. Default is 'diagram'.
120+
text. Global default: 'diagram'.
107121
108122
.. versionadded:: 0.23
109123
110124
pairwise_dist_chunk_size : int, default=None
111125
The number of row vectors per chunk for the accelerated pairwise-
112-
distances reduction backend. Default is 256 (suitable for most of
126+
distances reduction backend. Global default: 256 (suitable for most of
113127
modern laptops' caches and architectures).
114128
115129
Intended for easier benchmarking and testing of scikit-learn internals.
@@ -130,7 +144,7 @@ def set_config(
130144
131145
array_api_dispatch : bool, default=None
132146
Use Array API dispatching when inputs follow the Array API standard.
133-
Default is False.
147+
Global default: False.
134148
135149
See the :ref:`User Guide <array_api>` for more details.
136150
@@ -147,6 +161,8 @@ def set_config(
147161
- `"polars"`: Polars output
148162
- `None`: Transform configuration is unchanged
149163
164+
Global default: "default".
165+
150166
.. versionadded:: 1.2
151167
.. versionadded:: 1.4
152168
`"polars"` option was added.
@@ -161,13 +177,16 @@ def set_config(
161177
- `False`: Metadata routing is disabled, use the old syntax.
162178
- `None`: Configuration is unchanged
163179
180+
Global default: False.
181+
164182
.. versionadded:: 1.3
165183
166184
skip_parameter_validation : bool, default=None
167185
If `True`, disable the validation of the hyper-parameters' types and values in
168186
the fit method of estimators and for arguments passed to public helper
169187
functions. It can save time in some situations but can lead to low level
170188
crashes and exceptions with confusing error messages.
189+
Global default: False.
171190
172191
Note that for data parameters, such as `X` and `y`, only type validation is
173192
skipped but validation with `check_array` will continue to run.
@@ -225,46 +244,53 @@ def config_context(
225244
enable_metadata_routing=None,
226245
skip_parameter_validation=None,
227246
):
228-
"""Context manager for global scikit-learn configuration.
247+
"""Context manager to temporarily change the global scikit-learn configuration.
248+
249+
This context manager can be used to apply scikit-learn configuration changes within
250+
the scope of the with statement. Once the context exits, the global configuration is
251+
restored again.
252+
253+
The default global configurations (which take effect when scikit-learn is imported)
254+
are defined below in the parameter list.
229255
230256
Parameters
231257
----------
232258
assume_finite : bool, default=None
233259
If True, validation for finiteness will be skipped,
234260
saving time, but leading to potential crashes. If
235261
False, validation for finiteness will be performed,
236-
avoiding error. If None, the existing value won't change.
237-
The default value is False.
262+
avoiding error. If None, the existing configuration won't change.
263+
Global default: False.
238264
239265
working_memory : int, default=None
240266
If set, scikit-learn will attempt to limit the size of temporary arrays
241267
to this number of MiB (per job when parallelised), often saving both
242268
computation time and memory on expensive operations that can be
243-
performed in chunks. If None, the existing value won't change.
244-
The default value is 1024.
269+
performed in chunks. If None, the existing configuration won't change.
270+
Global default: 1024.
245271
246272
print_changed_only : bool, default=None
247273
If True, only the parameters that were set to non-default
248274
values will be printed when printing an estimator. For example,
249275
``print(SVC())`` while True will only print 'SVC()', but would print
250276
'SVC(C=1.0, cache_size=200, ...)' with all the non-changed parameters
251-
when False. If None, the existing value won't change.
252-
The default value is True.
277+
when False. If None, the existing configuration won't change.
278+
Global default: True.
253279
254280
.. versionchanged:: 0.23
255-
Default changed from False to True.
281+
Global default configuration changed from False to True.
256282
257283
display : {'text', 'diagram'}, default=None
258284
If 'diagram', estimators will be displayed as a diagram in a Jupyter
259285
lab or notebook context. If 'text', estimators will be displayed as
260-
text. If None, the existing value won't change.
261-
The default value is 'diagram'.
286+
text. If None, the existing configuration won't change.
287+
Global default: 'diagram'.
262288
263289
.. versionadded:: 0.23
264290
265291
pairwise_dist_chunk_size : int, default=None
266292
The number of row vectors per chunk for the accelerated pairwise-
267-
distances reduction backend. Default is 256 (suitable for most of
293+
distances reduction backend. Global default: 256 (suitable for most of
268294
modern laptops' caches and architectures).
269295
270296
Intended for easier benchmarking and testing of scikit-learn internals.
@@ -285,7 +311,7 @@ def config_context(
285311
286312
array_api_dispatch : bool, default=None
287313
Use Array API dispatching when inputs follow the Array API standard.
288-
Default is False.
314+
Global default: False.
289315
290316
See the :ref:`User Guide <array_api>` for more details.
291317
@@ -302,6 +328,8 @@ def config_context(
302328
- `"polars"`: Polars output
303329
- `None`: Transform configuration is unchanged
304330
331+
Global default: "default".
332+
305333
.. versionadded:: 1.2
306334
.. versionadded:: 1.4
307335
`"polars"` option was added.
@@ -316,13 +344,16 @@ def config_context(
316344
- `False`: Metadata routing is disabled, use the old syntax.
317345
- `None`: Configuration is unchanged
318346
347+
Global default: False.
348+
319349
.. versionadded:: 1.3
320350
321351
skip_parameter_validation : bool, default=None
322352
If `True`, disable the validation of the hyper-parameters' types and values in
323353
the fit method of estimators and for arguments passed to public helper
324354
functions. It can save time in some situations but can lead to low level
325355
crashes and exceptions with confusing error messages.
356+
Global default: False.
326357
327358
Note that for data parameters, such as `X` and `y`, only type validation is
328359
skipped but validation with `check_array` will continue to run.

0 commit comments

Comments
 (0)