Skip to content

DOC Ensures that LocallyLinearEmbedding passes numpydoc validation #21273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 change: 0 additions & 1 deletion maint_tools/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# List of modules ignored when checking for numpydoc validation.
DOCSTRING_IGNORE_LIST = [
"LabelSpreading",
"LocallyLinearEmbedding",
"MultiTaskElasticNetCV",
"OrthogonalMatchingPursuitCV",
"PassiveAggressiveRegressor",
Expand Down
88 changes: 51 additions & 37 deletions sklearn/manifold/_locally_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,42 +543,44 @@ def locally_linear_embedding(


class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator):
"""Locally Linear Embedding
"""Locally Linear Embedding.

Read more in the :ref:`User Guide <locally_linear_embedding>`.

Parameters
----------
n_neighbors : int, default=5
number of neighbors to consider for each point.
Number of neighbors to consider for each point.

n_components : int, default=2
number of coordinates for the manifold
Number of coordinates for the manifold.

reg : float, default=1e-3
regularization constant, multiplies the trace of the local covariance
Regularization constant, multiplies the trace of the local covariance
matrix of the distances.

eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'
auto : algorithm will attempt to choose the best method for input data
The solver used to compute the eigenvectors. The available options are:

arpack : use arnoldi iteration in shift-invert mode.
For this method, M may be a dense matrix, sparse matrix,
or general linear operator.
Warning: ARPACK can be unstable for some problems. It is
best to try several random seeds in order to check results.
- `'auto'` : algorithm will attempt to choose the best method for input
data.
- `'arpack'` : use arnoldi iteration in shift-invert mode. For this
method, M may be a dense matrix, sparse matrix, or general linear
operator.
- `'dense'` : use standard dense matrix operations for the eigenvalue
decomposition. For this method, M must be an array or matrix type.
This method should be avoided for large problems.

dense : use standard dense matrix operations for the eigenvalue
decomposition. For this method, M must be an array
or matrix type. This method should be avoided for
large problems.
.. warning::
ARPACK can be unstable for some problems. It is best to try several
random seeds in order to check results.

tol : float, default=1e-6
Tolerance for 'arpack' method
Not used if eigen_solver=='dense'.

max_iter : int, default=100
maximum number of iterations for the arpack solver.
Maximum number of iterations for the arpack solver.
Not used if eigen_solver=='dense'.

method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'
Expand All @@ -594,16 +596,16 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator

hessian_tol : float, default=1e-4
Tolerance for Hessian eigenmapping method.
Only used if ``method == 'hessian'``
Only used if ``method == 'hessian'``.

modified_tol : float, default=1e-12
Tolerance for modified LLE method.
Only used if ``method == 'modified'``
Only used if ``method == 'modified'``.

neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, \
default='auto'
algorithm to use for nearest neighbors search,
passed to neighbors.NearestNeighbors instance
Algorithm to use for nearest neighbors search, passed to
:class:`~sklearn.neighbors.NearestNeighbors` instance.

random_state : int, RandomState instance, default=None
Determines the random number generator when
Expand Down Expand Up @@ -639,17 +641,11 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
Stores nearest neighbors instance, including BallTree or KDtree
if applicable.

Examples
See Also
--------
>>> from sklearn.datasets import load_digits
>>> from sklearn.manifold import LocallyLinearEmbedding
>>> X, _ = load_digits(return_X_y=True)
>>> X.shape
(1797, 64)
>>> embedding = LocallyLinearEmbedding(n_components=2)
>>> X_transformed = embedding.fit_transform(X[:100])
>>> X_transformed.shape
(100, 2)
SpectralEmbedding : Spectral embedding for non-linear dimensionality
reduction.
TSNE : Distributed Stochastic Neighbor Embedding.

References
----------
Expand All @@ -665,6 +661,18 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
.. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear
dimensionality reduction via tangent space alignment.
Journal of Shanghai Univ. 8:406 (2004)

Examples
--------
>>> from sklearn.datasets import load_digits
>>> from sklearn.manifold import LocallyLinearEmbedding
>>> X, _ = load_digits(return_X_y=True)
>>> X.shape
(1797, 64)
>>> embedding = LocallyLinearEmbedding(n_components=2)
>>> X_transformed = embedding.fit_transform(X[:100])
>>> X_transformed.shape
(100, 2)
"""

def __init__(
Expand Down Expand Up @@ -722,18 +730,20 @@ def _fit_transform(self, X):
)

def fit(self, X, y=None):
"""Compute the embedding vectors for data X
"""Compute the embedding vectors for data X.

Parameters
----------
X : array-like of shape [n_samples, n_features]
training set.
X : array-like of shape (n_samples, n_features)
Training set.

y : Ignored
Not used, present here for API consistency by convention.

Returns
-------
self : returns an instance of self.
self : object
Fitted `LocallyLinearEmbedding` class instance.
"""
self._fit_transform(X)
return self
Expand All @@ -743,14 +753,16 @@ def fit_transform(self, X, y=None):

Parameters
----------
X : array-like of shape [n_samples, n_features]
training set.
X : array-like of shape (n_samples, n_features)
Training set.

y : Ignored
Not used, present here for API consistency by convention.

Returns
-------
X_new : array-like, shape (n_samples, n_components)
Returns the instance itself.
"""
self._fit_transform(X)
return self.embedding_
Expand All @@ -762,15 +774,17 @@ def transform(self, X):
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training set.

Returns
-------
X_new : array, shape = [n_samples, n_components]
X_new : ndarray of shape (n_samples, n_components)
Returns the instance itself.

Notes
-----
Because of scaling performed by this method, it is discouraged to use
it together with methods that are not scale-invariant (like SVMs)
it together with methods that are not scale-invariant (like SVMs).
"""
check_is_fitted(self)

Expand Down