8000 DOC Improved clarity, consistency and formatting for `fastica`/`FastI… · scikit-learn/scikit-learn@206b585 · GitHub
[go: up one dir, main page]

Skip to content

Commit 206b585

Browse files
Micky774glemaitre
authored andcommitted
DOC Improved clarity, consistency and formatting for fastica/FastICA docstrings (#23309)
* Improved clarity, consistency and formatting for FastICA docstrings * Updated wording
1 parent 3b068e3 commit 206b585

File tree

2 files changed

+37
-31
lines changed

2 files changed

+37
-31
lines changed

sklearn/decomposition/_fastica.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,23 @@ def fastica(
180180
`n_features` is the number of features.
181181
182182
n_components : int, default=None
183-
Number of components to extract. If None no dimension reduction
184-
is performed.
183+
Number of components to use. If None is passed, all are used.
185184
186185
algorithm : {'parallel', 'deflation'}, default='parallel'
187-
Apply a parallel or deflational FASTICA algorithm.
186+
Specify which algorithm to use for FastICA.
188187
189188
whiten : str or bool, default="warn"
190189
Specify the whitening strategy to use.
191-
If 'arbitrary-variance' (default), a whitening with variance arbitrary is used.
192-
If 'unit-variance', the whitening matrix is rescaled to ensure that each
193-
recovered source has unit variance.
194-
If False, the data is already considered to be whitened, and no
195-
whitening is performed.
190+
191+
- If 'arbitrary-variance' (default), a whitening with variance
192+
arbitrary is used.
193+
- If 'unit-variance', the whitening matrix is rescaled to ensure that
194+
each recovered source has unit variance.
195+
- If False, the data is already considered to be whitened, and no
196+
whitening is performed.
196197
197198
.. deprecated:: 1.1
198-
From version 1.3, `whiten='unit-variance'` will be used by default.
199+
Starting in v1.3, `whiten='unit-variance'` will be used by default.
199200
`whiten=True` is deprecated from 1.1 and will raise ValueError in 1.3.
200201
Use `whiten=arbitrary-variance` instead.
201202
@@ -206,10 +207,10 @@ def fastica(
206207
You can also provide your own function. It should return a tuple
207208
containing the value of the function, and of its derivative, in the
208209
point. The derivative should be averaged along its last dimension.
209-
Example:
210+
Example::
210211
211-
def my_g(x):
212-
return x ** 3, np.mean(3 * x ** 2, axis=-1)
212+
def my_g(x):
213+
return x ** 3, (3 * x ** 2).mean(axis=-1)
213214
214215
fun_args : dict, default=None
215216
Arguments to send to the functional form.
@@ -219,13 +220,13 @@ def my_g(x):
219220
max_iter : int, default=200
220221
Maximum number of iterations to perform.
221222
222-
tol : float, default=1e-04
223+
tol : float, default=1e-4
223224
A positive scalar giving the tolerance at which the
224225
un-mixing matrix is considered to have converged.
225226
226227
w_init : ndarray of shape (n_components, n_components), default=None
227-
Initial un-mixing array of dimension (n.comp,n.comp).
228-
If None (default) then an array of normal r.v.'s is used.
228+
Initial un-mixing array. If `w_init=None`, then an array of values
229+
drawn from a normal distribution is used.
229230
230231
random_state : int, RandomState instance or None, default=None
231232
Used to initialize ``w_init`` when not specified, with a
@@ -332,18 +333,20 @@ class FastICA(_ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator)
332333
Number of components to use. If None is passed, all are used.
333334
334335
algorithm : {'parallel', 'deflation'}, default='parallel'
335-
Apply parallel or deflational algorithm for FastICA.
336+
Specify which algorithm to use for FastICA.
336337
337338
whiten : str or bool, default="warn"
338339
Specify the whitening strategy to use.
339-
If 'arbitrary-variance' (default), a whitening with variance arbitrary is used.
340-
If 'unit-variance', the whitening matrix is rescaled to ensure that each
341-
recovered source has unit variance.
342-
If False, the data is already considered to be whitened, and no
343-
whitening is performed.
340+
341+
- If 'arbitrary-variance' (default), a whitening with variance
342+
arbitrary is used.
343+
- If 'unit-variance', the whitening matrix is rescaled to ensure that
344+
each recovered source has unit variance.
345+
- If False, the data is already considered to be whitened, and no
346+
whitening is performed.
344347
345348
.. deprecated:: 1.1
346-
From version 1.3 whiten='unit-variance' will be used by default.
349+
Starting in v1.3, `whiten='unit-variance'` will be used by default.
347350
`whiten=True` is deprecated from 1.1 and will raise ValueError in 1.3.
348351
Use `whiten=arbitrary-variance` instead.
349352
@@ -353,24 +356,27 @@ class FastICA(_ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator)
353356
or 'cube'.
354357
You can also provide your own function. It should return a tuple
355358
containing the value of the function, and of its derivative, in the
356-
point. Example::
359+
point. The derivative should be averaged along its last dimension.
360+
Example::
357361
358362
def my_g(x):
359363
return x ** 3, (3 * x ** 2).mean(axis=-1)
360364
361365
fun_args : dict, default=None
362366
Arguments to send to the functional form.
363-
If empty and if fun='logcosh', fun_args will take value
367+
If empty or None and if fun='logcosh', fun_args will take value
364368
{'alpha' : 1.0}.
365369
366370
max_iter : int, default=200
367371
Maximum number of iterations during fit.
368372
369373
tol : float, default=1e-4
370-
Tolerance on update at each iteration.
374+
A positive scalar giving the tolerance at which the
375+
un-mixing matrix is considered to have converged.
371376
372377
w_init : ndarray of shape (n_components, n_components), default=None
373-
The mixing matrix to be used to initialize the algorithm.
378+
Initial un-mixing array. If `w_init=None`, then an array of values
379+
drawn from a normal distribution is used.
374380
375381
random_state : int, RandomState instance or None, default=None
376382
Used to initialize ``w_init`` when not specified, with a
@@ -486,14 +492,14 @@ def _fit(self, X, compute_sources=False):
486492

487493
if self._whiten == "warn":
488494
warnings.warn(
489-
"From version 1.3 whiten='unit-variance' will be used by default.",
495+
"Starting in v1.3, whiten='unit-variance' will be used by default.",
490496
FutureWarning,
491497
)
492498
self._whiten = "arbitrary-variance"
493499

494500
if self._whiten is True:
495501
warnings.warn(
496-
"From version 1.3 whiten=True should be specified as "
502+
"Starting in v1.3, whiten=True should be specified as "
497503
"whiten='arbitrary-variance' (its current behaviour). This "
498504
"behavior is deprecated in 1.1 and will raise ValueError in 1.3.",
499505
FutureWarning,

sklearn/decomposition/tests/test_fastica.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_fastica_return_dtypes(global_dtype):
7171

7272
# FIXME remove filter in 1.3
7373
@pytest.mark.filterwa C18F rnings(
74-
"ignore:From version 1.3 whiten='unit-variance' will be used by default."
74+
"ignore:Starting in v1.3, whiten='unit-variance' will be used by default."
7575
)
7676
@pytest.mark.parametrize("add_noise", [True, False])
7777
def test_fastica_simple(add_noise, global_random_seed, global_dtype):
@@ -353,7 +353,7 @@ def test_inverse_transform(
353353

354354
# FIXME remove filter in 1.3
355355
@pytest.mark.filterwarnings(
356-
"ignore:From version 1.3 whiten='unit-variance' will be used by default."
356+
"ignore:Starting in v1.3, whiten='unit-variance' will be used by default."
357357
)
358358
def test_fastica_errors():
359359
n_features = 3
@@ -398,7 +398,7 @@ def test_fastica_whiten_default_value_deprecation(ica):
398398
"""
399399
rng = np.random.RandomState(0)
400400
X = rng.random_sample((100, 10))
401-
with pytest.warns(FutureWarning, match=r"From version 1.3 whiten="):
401+
with pytest.warns(FutureWarning, match=r"Starting in v1.3, whiten="):
402402
ica.fit(X)
403403
assert ica._whiten == "arbitrary-variance"
404404

0 commit comments

Comments
 (0)
0