8000 DOC specify the meaning of W=None and H=None in sklearn.decomposition… · scikit-learn/scikit-learn@a70954d · GitHub
[go: up one dir, main page]

Skip to content

Commit a70954d

Browse files
DOC specify the meaning of W=None and H=None in sklearn.decomposition.non_negative_factorization (#25770)
1 parent 1dc0dd4 commit a70954d

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

sklearn/decomposition/_nmf.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,16 @@ def non_negative_factorization(
959959
Constant matrix.
960960
961961
W : array-like of shape (n_samples, n_components), default=None
962-
If init='custom', it is used as initial guess for the solution.
962+
If `init='custom'`, it is used as initial guess for the solution.
963+
If `update_H=False`, it is initialised as an array of zeros, unless
964+
`solver='mu'`, then it is filled with values calculated by
965+
`np.sqrt(X.mean() / self._n_components)`.
966+
If `None`, uses the initialisation method specified in `init`.
963967
964968
H : array-like of shape (n_components, n_features), default=None
965-
If init='custom', it is used as initial guess for the solution.
966-
If update_H=False, it is used as a constant, to solve for W only.
969+
If `init='custom'`, it is used as initial guess for the solution.
970+
If `update_H=False`, it is used as a constant, to solve for W only.
971+
If `None`, uses the initialisation method specified in `init`.
967972
968973
n_components : int, default=None
969974
Number of components, if n_components is not set all features
@@ -984,8 +989,8 @@ def non_negative_factorization(
984989
- 'nndsvdar': NNDSVD with zeros filled with small random values
985990
(generally faster, less accurate alternative to NNDSVDa
986991
for when sparsity is not desired)
987-
- 'custom': use custom matrices W and H if `update_H=True`. If
988-
`update_H=False`, then only custom matrix H is used.
992+
- 'custom': If `update_H=True`, use custom matrices W and H which must both
993+
be provided. If `update_H=False`, then only custom matrix H is used.
989994
990995
.. versionchanged:: 0.23
991996
The default value of `init` changed from 'random' to None in 0.23.
@@ -1327,7 +1332,7 @@ class NMF(_BaseNMF):
13271332
otherwise random.
13281333
13291334
- `'random'`: non-negative random matrices, scaled with:
1330-
sqrt(X.mean() / n_components)
1335+
`sqrt(X.mean() / n_components)`
13311336
13321337
- `'nndsvd'`: Nonnegative Double Singular Value Decomposition (NNDSVD)
13331338
initialization (better for sparseness)
@@ -1339,7 +1344,7 @@ class NMF(_BaseNMF):
13391344
(generally faster, less accurate alternative to NNDSVDa
13401345
for when sparsity is not desired)
13411346
1342-
- `'custom'`: use custom matrices W and H
1347+
- `'custom'`: Use custom matrices `W` and `H` which must both be provided.
13431348
13441349
.. versionchanged:: 1.1
13451350
When `init=None` and n_components is less than n_samples and n_features
@@ -1545,11 +1550,13 @@ def fit_transform(self, X, y=None, W=None, H=None):
15451550
y : Ignored
15461551
Not used, present for API consistency by convention.
15471552
1548-
W : array-like of shape (n_samples, n_components)
1549-
If init='custom', it is used as initial guess for the solution.
1553+
W : array-like of shape (n_samples, n_components), default=None
1554+
If `init='custom'`, it is used as initial guess for the solution.
1555+
If `None`, uses the initialisation method specified in `init`.
15501556
1551-
H : array-like of shape (n_components, n_features)
1552-
If init='custom', it is used as initial guess for the solution.
1557+
H : array-like of shape (n_components, n_features), default=None
1558+
If `init='custom'`, it is used as initial guess for the solution.
1559+
If `None`, uses the initialisation method specified in `init`.
15531560
15541561
Returns
15551562
-------
@@ -1585,12 +1592,17 @@ def _fit_transform(self, X, y=None, W=None, H=None, update_H=True):
15851592
15861593
y : Ignored
15871594
1588-
W : array-like of shape (n_samples, n_components)
1589-
If init='custom', it is used as initial guess for the solution.
1595+
W : array-like of shape (n_samples, n_components), default=None
1596+
If `init='custom'`, it is used as initial guess for the solution.
1597+
If `update_H=False`, it is initialised as an array of zeros, unless
1598+
`solver='mu'`, then it is filled with values calculated by
1599+
`np.sqrt(X.mean() / self._n_components)`.
1600+
If `None`, uses the initialisation method specified in `init`.
15901601
1591-
H : array-like of shape (n_components, n_features)
1592-
If init='custom', it is used as initial guess for the solution.
1593-
If update_H=False, it is used as a constant, to solve for W only.
1602+
H : array-like of shape (n_components, n_features), default=None
1603+
If `init='custom'`, it is used as initial guess for the solution.
1604+
If `update_H=False`, it is used as a constant, to solve for W only.
1605+
If `None`, uses the initialisation method specified in `init`.
15941606
15951607
update_H : bool, default=True
15961608
If True, both W and H will be estimated from initial guesses,
@@ -1765,7 +1777,7 @@ class MiniBatchNMF(_BaseNMF):
17651777
(generally faster, less accurate alternative to NNDSVDa
17661778
for when sparsity is not desired).
17671779
1768-
- `'custom'`: use custom matrices `W` and `H`
1780+
- `'custom'`: Use custom matrices `W` and `H` which must both be provided.
17691781
17701782
batch_size : int, default=1024
17711783
Number of samples in each mini-batch. Large batch sizes
@@ -2124,9 +2136,11 @@ def fit_transform(self, X, y=None, W=None, H=None):
21242136
21252137
W : array-like of shape (n_samples, n_components), default=None
21262138
If `init='custom'`, it is used as initial guess for the solution.
2139+
If `None`, uses the initialisation method specified in `init`.
21272140
21282141
H : array-like of shape (n_components, n_features), default=None
21292142
If `init='custom'`, it is used as initial guess for the solution.
2143+
If `None`, uses the initialisation method specified in `init`.
21302144
21312145
Returns
21322146
-------
@@ -2162,11 +2176,16 @@ def _fit_transform(self, X, W=None, H=None, update_H=True):
21622176
Data matrix to be decomposed.
21632177
21642178
W : array-like of shape (n_samples, n_components), default=None
2165-
If init='custom', it is used as initial guess for the solution.
2179+
If `init='custom'`, it is used as initial guess for the solution.
2180+
If `update_H=False`, it is initialised as an array of zeros, unless
2181+
`solver='mu'`, then it is filled with values calculated by
2182+
`np.sqrt(X.mean() / self._n_components)`.
2183+
If `None`, uses the initialisation method specified in `init`.
21662184
21672185
H : array-like of shape (n_components, n_features), default=None
2168-
If init='custom', it is used as initial guess for the solution.
2169-
If update_H=False, it is used as a constant, to solve for W only.
2186+
If `init='custom'`, it is used as initial guess for the solution.
2187+
If `update_H=False`, it is used as a constant, to solve for W only.
2188+
If `None`, uses the initialisation method specified in `init`.
21702189
21712190
update_H : bool, default=True
21722191
If True, both W and H will be estimated from initial guesses,

0 commit comments

Comments
 (0)
0