8000 DOC Add None as valid option to random_state (#18234) · alexshacked/scikit-learn@30f201f · GitHub < 8000 link rel="manifest" href="/manifest.json" crossOrigin="use-credentials">
[go: up one dir, main page]

Skip to content

Commit 30f201f

Browse files
authored
DOC Add None as valid option to random_state (scikit-learn#18234)
1 parent a675319 commit 30f201f

File tree

8 files changed

+55
-55
lines changed

8 files changed

+55
-55
lines changed

sklearn/decomposition/_dict_learning.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Dictionary learning
1+
""" Dictionary learning.
22
"""
33
# Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort
44
# License: BSD 3 clause
@@ -34,7 +34,7 @@ def _sparse_encode(X, dictionary, gram, cov=None, algorithm='lasso_lars',
3434
regularization=None, copy_cov=True,
3535
init=None, max_iter=1000, check_input=True, verbose 8000 =0,
3636
positive=False):
37-
"""Generic sparse coding
37+
"""Generic sparse coding.
3838
3939
Each column of the result is the solution to a Lasso problem.
4040
@@ -375,7 +375,7 @@ def _update_dict(dictionary, Y, code, verbose=False, return_r2=False,
375375
Whether to compute and return the residual sum of squares corresponding
376376
to the computed solution.
377377
378-
random_state : int or RandomState instance or None, default=None
378+
random_state : int, RandomState instance or None, default=None
379379
Used for randomly initializing the dictionary. Pass an int for
380380
reproducible results across multiple function calls.
381381
See :term:`Glossary <random_state>`.
@@ -455,7 +455,7 @@ def dict_learning(X, n_components, *, alpha, max_iter=100, tol=1e-8,
455455
456456
Parameters
457457
----------
458-
X : array of shape (n_samples, n_features)
458+
X : ndarray of shape (n_samples, n_features)
459459
Data matrix.
460460
461461
n_components : int
@@ -497,7 +497,7 @@ def dict_learning(X, n_components, *, alpha, max_iter=100, tol=1e-8,
497497
verbose : bool, default=False
498498
To control the verbosity of the procedure.
499499
500-
random_state : int or RandomState instance or None, default=None
500+
random_state : int, RandomState instance or None, default=None
501501
Used for randomly initializing the dictionary. Pass an int for
502502
reproducible results across multiple function calls.
503503
See :term:`Glossary <random_state>`.
@@ -704,7 +704,7 @@ def dict_learning_online(X, n_components=2, *, alpha=1, n_iter=100,
704704
Number of previous iterations completed on the dictionary used for
705705
initialization.
706706
707-
random_state : int or RandomState instance or None, default=None
707+
random_state : int, RandomState instance or None, default=None
708708
Used for initializing the dictionary when ``dict_init`` is not
709709
specified, randomly shuffling the data when ``shuffle`` is set to
710710
``True``, and updating the dictionary. Pass an int for reproducible
@@ -1102,13 +1102,13 @@ def transform(self, X, y=None):
11021102
11031103
Parameters
11041104
----------
1105-
X : array of shape (n_samples, n_features)
1105+
X : ndarray of shape (n_samples, n_features)
11061106
Test data to be transformed, must have the same number of
11071107
features as the data used to train the model.
11081108
11091109
Returns
11101110
-------
1111-
X_new : array of shape (n_samples, n_components)
1111+
X_new : ndarray of shape (n_samples, n_components)
11121112
Transformed data.
11131113
"""
11141114
return super()._transform(X, self.dictionary)
@@ -1217,7 +1217,7 @@ class DictionaryLearning(_BaseSparseCoding, BaseEstimator):
12171217
its negative part and its positive part. This can improve the
12181218
performance of downstream classifiers.
12191219
1220-
random_state : int or RandomState instance or None, default=None
1220+
random_state : int, RandomState instance or None, default=None
12211221
Used for initializing the dictionary when ``dict_init`` is not
12221222
specified, randomly shuffling the data when ``shuffle`` is set to
12231223
``True``, and updating the dictionary. Pass an int for reproducible
@@ -1445,7 +1445,7 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
14451445
its negative part and its positive part. This can improve the
14461446
performance of downstream classifiers.
14471447
1448-
random_state : int or RandomState instance or None, default=None
1448+
random_state : int, RandomState instance or None, default=None
14491449
Used for initializing the dictionary when ``dict_init`` is not
14501450
specified, randomly shuffling the data when ``shuffle`` is set to
14511451
``True``, and updating the dictionary. Pass an int for reproducible
@@ -1608,7 +1608,7 @@ def partial_fit(self, X, y=None, iter_offset=None):
16081608
16091609
y : Ignored
16101610
1611-
iter_offset : integer, default=None
1611+
iter_offset : int, default=None
16121612
The number of iteration on data batches that has been
16131613
performed before this call to partial_fit. This is optional:
16141614
if no number is passed, the memory of the object is

sklearn/decomposition/_fastica.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
def _gs_decorrelation(w, W, j):
2929
"""
30-
Orthonormalize w wrt the first j rows of W
30+
Orthonormalize w wrt the first j rows of W.
3131
3232
Parameters
3333
----------
@@ -204,7 +204,7 @@ def my_g(x):
204204
Initial un-mixing array of dimension (n.comp,n.comp).
205205
If None (default) then an array of normal r.v.'s is used.
206206
207-
random_state : int or RandomState instance, default=None
207+
random_state : int, RandomState instance or None, default=None
208208
Used to initialize ``w_init`` when not specified, with a
209209
normal distribution. Pass an int, for reproducible results
210210
across multiple function calls.
@@ -343,7 +343,7 @@ def my_g(x):
343343
w_init : ndarray of shape (n_components, n_components), default=None
344344
The mixing matrix to be used to initialize the algorithm.
345345
346-
random_state : int or RandomState instance, default=None
346+
random_state : int, RandomState instance or None, default=None
347347
Used to initialize ``w_init`` when not specified, with a
348348
normal distribution. Pass an int, for reproducible results
349349
across multiple function calls.

sklearn/decomposition/_kernel_pca.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Kernel Principal Components Analysis"""
1+
"""Kernel Principal Components Analysis."""
22

33
# Author: Mathieu Blondel <mathieu@mblondel.org>
44
# License: BSD 3 clause
@@ -18,7 +18,7 @@
1818

1919

2020
class KernelPCA(TransformerMixin, BaseEstimator):
21-
"""Kernel Principal component analysis (KPCA)
21+
"""Kernel Principal component analysis (KPCA).
2222
2323
Non-linear dimensionality reduction through the use of kernels (see
2424
:ref:`metrics`).
@@ -78,7 +78,7 @@ class KernelPCA(TransformerMixin, BaseEstimator):
7878
When n_components is None, this parameter is ignored and components
7979
with zero eigenvalues are removed regardless.
8080
81-
random_state : int or RandomState instance, default=None
81+
random_state : int, RandomState instance or None, default=None
8282
Used when ``eigen_solver`` == 'arpack'. Pass an int for reproducible
8383
results across multiple function calls.
8484
See :term:`Glossary <random_state>`.

sklearn/decomposition/_lda.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class LatentDirichletAllocation(TransformerMixin, BaseEstimator):
224224
verbose : int, default=0
225225
Verbosity level.
226226
227-
random_state : int or RandomState instance, default=None
227+
random_state : int, RandomState instance or None, default=None
228228
Pass an int for reproducible results across multiple function calls.
229229
See :term:`Glossary <random_state>`.
230230

sklearn/decomposition/_nmf.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Non-negative matrix factorization
1+
""" Non-negative matrix factorization.
22
"""
33
# Author: Vlad Niculae
44
# Lars Buitinck
@@ -25,14 +25,14 @@
2525

2626

2727
def norm(x):
28-
"""Dot product-based Euclidean norm implementation
28+
"""Dot product-based Euclidean norm implementation.
2929
3030
See: http://fseoane.net/blog/2011/computing-the-vector-norm/
3131
3232
Parameters
3333
----------
3434
x : array-like
35-
Vector for which to compute the norm
35+
Vector for which to compute the norm.
3636
"""
3737
return sqrt(squared_norm(x))
3838

@@ -43,9 +43,9 @@ def trace_dot(X, Y):
4343
Parameters
4444
----------
4545
X : array-like
46-
First matrix
46+
First matrix.
4747
Y : array-like
48-
Second matrix
48+
Second matrix.
4949
"""
5050
return np.dot(X.ravel(), Y.ravel())
5151

@@ -85,7 +85,7 @@ def _beta_divergence(X, W, H, beta, square_root=False):
8585
Returns
8686
-------
8787
res : float
88-
Beta divergence of X and np.dot(X, H)
88+
Beta divergence of X and np.dot(X, H).
8989
"""
9090
beta = _beta_loss_to_float(beta)
9191

@@ -187,7 +187,7 @@ def _special_sparse_dot(W, H, X):
187187

188188

189189
def _compute_regularization(alpha, l1_ratio, regularization):
190-
"""Compute L1 and L2 regularization coefficients for W and H"""
190+
"""Compute L1 and L2 regularization coefficients for W and H."""
191191
alpha_H = 0.
192192
alpha_W = 0.
193193
if regularization in ('both', 'components'):
@@ -233,7 +233,7 @@ def _check_string_param(solver, regularization, beta_loss, init):
233233

234234

235235
def _beta_loss_to_float(beta_loss):
236-
"""Convert string beta_loss to float"""
236+
"""Convert string beta_loss to float."""
237237
allowed_beta_loss = {'frobenius': 2,
238238
'kullback-leibler': 1,
239239
'itakura-saito': 0}
@@ -252,7 +252,7 @@ def _initialize_nmf(X, n_components, init=None, eps=1e-6,
252252
"""Algorithms for NMF initialization.
253253
254254
Computes an initial guess for the non-negative
255-
rank k matrix approximation for X: X = WH
255+
rank k matrix approximation for X: X = WH.
256256
257257
Parameters
258258
----------
@@ -288,18 +288,18 @@ def _initialize_nmf(X, n_components, init=None, eps=1e-6,
288288
eps : float, default=1e-6
289289
Truncate all values less then this in output to zero.
290290
291-
random_state : int or RandomState instance, default=None
291+
random_state : int, RandomState instance or None, default=None
292292
Used when ``init`` == 'nndsvdar' or 'random'. Pass an int for
293293
reproducible results across multiple function calls.
294294
See :term:`Glossary <random_state>`.
295295
296296
Returns
297297
-------
298298
W : array-like of shape (n_samples, n_components)
299-
Initial guesses for solving X ~= WH
299+
Initial guesses for solving X ~= WH.
300300
301301
H : array-like of shape (n_components, n_features)
302-
Initial guesses for solving X ~= WH
302+
Initial guesses for solving X ~= WH.
303303
304304
References
305305
----------
@@ -395,11 +395,11 @@ def _initialize_nmf(X, n_components, init=None, eps=1e-6,
395395

396396
def _update_coordinate_descent(X, W, Ht, l1_reg, l2_reg, shuffle,
397397
random_state):
398-
"""Helper function for _fit_coordinate_descent
398+
"""Helper function for _fit_coordinate_descent.
399399
400400
Update W to minimize the objective function, iterating once over all
401401
coordinates. By symmetry, to update H, one can call
402-
_update_coordinate_descent(X.T, Ht, W, ...)
402+
_update_coordinate_descent(X.T, Ht, W, ...).
403403
404404
"""
405405
n_components = Ht.shape[1]
@@ -472,7 +472,7 @@ def _fit_coordinate_descent(X, W, H, tol=1e-4, max_iter=200, l1_reg_W=0,
472472
shuffle : bool, default=False
473473
If true, randomize the order of coordinates in the CD solver.
474474
475-
random_state : int or RandomState instance, default=None
475+
random_state : int, RandomState instance or None, default=None
476476
Used to randomize the coordinates in the CD solver, when
477477
``shuffle`` is set to ``True``. Pass an int for reproducible
478478
results across multiple function calls.
@@ -532,7 +532,7 @@ def _fit_coordinate_descent(X, W, H, tol=1e-4, max_iter=200, l1_reg_W=0,
532532

533533
def _multiplicative_update_w(X, W, H, beta_loss, l1_reg_W, l2_reg_W, gamma,
534534
H_sum=None, HHt=None, XHt=None, update_H=True):
535-
"""update W in Multiplicative Update NMF"""
535+
"""Update W in Multiplicative Update NMF."""
536536
if beta_loss == 2:
537537
# Numerator
538538
if XHt is None:
@@ -626,7 +626,7 @@ def _multiplicative_update_w(X, W, H, beta_loss, l1_reg_W, l2_reg_W, gamma,
626626

627627

628628
def _multiplicative_update_h(X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma):
629-
"""update H in Multiplicative Update NMF"""
629+
"""Update H in Multiplicative Update NMF."""
630630
if beta_loss == 2:
631631
numerator = safe_sparse_dot(W.T, X)
632632
denominator = np.linalg.multi_dot([W.T, W, H])
@@ -711,7 +711,7 @@ def _fit_multiplicative_update(X, W, H, beta_loss='frobenius',
711711
max_iter=200, tol=1e-4,
712712
l1_reg_W=0, l1_reg_H=0, l2_reg_W=0, l2_reg_H=0,
713713
update_H=True, verbose=0):
714-
"""Compute Non-negative Matrix Factorization with Multiplicative Update
714+
"""Compute Non-negative Matrix Factorization with Multiplicative Update.
715715
716716
The objective function is _beta_divergence(X, WH) and is minimized with an
717717
alternating minimization of W and H. Each minimization is done with a
@@ -849,7 +849,7 @@ def non_negative_factorization(X, W=None, H=None, n_components=None, *,
849849
max_iter=200, alpha=0., l1_ratio=0.,
850850
regularization=None, random_state=None,
851851
verbose=0, shuffle=False):
852-
"""Compute Non-negative Matrix Factorization (NMF)
852+
"""Compute Non-negative Matrix Factorization (NMF).
853853
854854
Find two non-negative matrices (W, H) whose product approximates the non-
855855
negative matrix X. This factorization can be used for example for
@@ -970,7 +970,7 @@ def non_negative_factorization(X, W=None, H=None, n_components=None, *,
970970
Select whether the regularization affects the components (H), the
971971
transformation (W), both or none of them.
972972
973-
random_state : int or RandomState instance, default=None
973+
random_state : int, RandomState instance or None, default=None
974974
Used for NMF initialisation (when ``init`` == 'nndsvdar' or
975975
'random'), and in Coordinate Descent. Pass an int for reproducible
976976
results across multiple function calls.
@@ -1086,7 +1086,7 @@ def non_negative_factorization(X, W=None, H=None, n_components=None, *,
10861086

10871087

10881088
class NMF(TransformerMixin, BaseEstimator):
1089-
"""Non-Negative Matrix Factorization (NMF)
1089+
"""Non-Negative Matrix Factorization (NMF).
10901090
10911091
Find two non-negative matrices (W, H) whose product approximates the non-
10921092
negative matrix X. This factorization can be used for example for
@@ -1175,7 +1175,7 @@ class NMF(TransformerMixin, BaseEstimator):
11751175
max_iter : int, default=200
11761176
Maximum number of iterations before timing out.
11771177
1178-
random_state : int or RandomState instance, default=None
1178+
random_state : int, RandomState instance or None, default=None
11791179
Used for initialisation (when ``init`` == 'nndsvdar' or
11801180
'random'), and in Coordinate Descent. Pass an int for reproducible
11811181
results across multiple function calls.
@@ -1334,17 +1334,17 @@ def fit(self, X, y=None, **params):
13341334
return self
13351335

13361336
def transform(self, X):
1337-
"""Transform the data X according to the fitted NMF model
1337+
"""Transform the data X according to the fitted NMF model.
13381338
13391339
Parameters
13401340
----------
13411341
X : {array-like, sparse matrix} of shape (n_samples, n_features)
1342-
Data matrix to be transformed by the model
1342+
Data matrix to be transformed by the model.
13431343
13441344
Returns
13451345
-------
13461346
W : ndarray of shape (n_samples, n_components)
1347-
Transformed data
1347+
Transformed data.
13481348
"""
13491349
check_is_fitted(self)
13501350

@@ -1365,12 +1365,12 @@ def inverse_transform(self, W):
13651365
Parameters
13661366
----------
13671367
W : {ndarray, sparse matrix} of shape (n_samples, n_components)
1368-
Transformed data matrix
1368+
Transformed data matrix.
13691369
13701370
Returns
13711371
-------
13721372
X : {ndarray, sparse matrix} of shape (n_samples, n_features)
1373-
Data matrix of original shape
1373+
Data matrix of original shape.
13741374
13751375
.. versionadded:: 0.18
13761376
"""

0 commit comments

Comments
 (0)
0