8000 DOC Ensures that `sklearn.utils.extmath.randomized_svd` passes numpyd… · scikit-learn/scikit-learn@aa7fd7a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa7fd7a

Browse files
awinmlglemaitre
andauthored
DOC Ensures that sklearn.utils.extmath.randomized_svd passes numpydoc validation (#24607)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
1 parent 5b45d1f commit aa7fd7a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

sklearn/tests/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
FUNCTION_DOCSTRING_IGNORE_LIST = [
1515
"sklearn.utils.extmath.fast_logdet",
16-
"sklearn.utils.extmath.randomized_svd",
1716
"sklearn.utils.metaestimators.if_delegate_has_method",
1817
]
1918
FUNCTION_DOCSTRING_IGNORE_LIST = set(FUNCTION_DOCSTRING_IGNORE_LIST)

sklearn/utils/extmath.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def randomized_svd(
274274
random_state="warn",
275275
svd_lapack_driver="gesdd",
276276
):
277-
"""Computes a truncated randomized SVD.
277+
"""Compute a truncated randomized SVD.
278278
279279
This method solves the fixed-rank approximation problem described in [1]_
280280
(problem (1.5), p5).
@@ -357,6 +357,15 @@ def randomized_svd(
357357
358358
.. versionadded:: 1.2
359359
360+
Returns
361+
-------
362+
u : ndarray of shape (n_samples, n_components)
363+
Unitary matrix having left singular vectors with signs flipped as columns.
364+
s : ndarray of shape (n_components,)
365+
The singular values, sorted in non-increasing order.
366+
vh : ndarray of shape (n_components, n_features)
367+
Unitary matrix having right singular vectors with signs flipped as rows.
368+
360369
Notes
361370
-----
362371
This algorithm finds a (usually very good) approximate truncated
@@ -381,6 +390,17 @@ def randomized_svd(
381390
382391
.. [3] An implementation of a randomized algorithm for principal component
383392
analysis A. Szlam et al. 2014
393+
394+
Examples
395+
--------
396+
>>> import numpy as np
397+
>>> from sklearn.utils.extmath import randomized_svd
398+
>>> a = np.array([[1, 2, 3, 5],
399+
... [3, 4, 5, 6],
400+
... [7, 8, 9, 10]])
401+
>>> U, s, Vh = randomized_svd(a, n_components=2, random_state=0)
402+
>>> U.shape, s.shape, Vh.shape
403+
((3, 2), (2,), (2, 4))
384404
"""
385405
if isinstance(M, (sparse.lil_matrix, sparse.dok_matrix)):
386406
warnings.warn(

0 commit comments

Comments
 (0)
0