Skip to content

Commit eb6e35e

Browse files
DOC Ensures that LocallyLinearEmbedding passes numpydoc validation (#21273)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
1 parent a17430c commit eb6e35e

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed

maint_tools/test_docstrings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# List of modules ignored when checking for numpydoc validation.
1515
DOCSTRING_IGNORE_LIST = [
1616
"LabelSpreading",
17-
"LocallyLinearEmbedding",
1817
"MultiTaskElasticNetCV",
1918
"OrthogonalMatchingPursuitCV",
2019
"PassiveAggressiveRegressor",

sklearn/manifold/_locally_linear.py

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -543,42 +543,44 @@ def locally_linear_embedding(
543543

544544

545545
class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator):
546-
"""Locally Linear Embedding
546+
"""Locally Linear Embedding.
547547
548548
Read more in the :ref:`User Guide <locally_linear_embedding>`.
549549
550550
Parameters
551551
----------
552552
n_neighbors : int, default=5
553-
number of neighbors to consider for each point.
553+
Number of neighbors to consider for each point.
554554
555555
n_components : int, default=2
556-
number of coordinates for the manifold
556+
Number of coordinates for the manifold.
557557
558558
reg : float, default=1e-3
559-
regularization constant, multiplies the trace of the local covariance
559+
Regularization constant, multiplies the trace of the local covariance
560560
matrix of the distances.
561561
562562
eigen_solver : {'auto', 'arpack', 'dense'}, default='auto'
563-
auto : algorithm will attempt to choose the best method for input data
563+
The solver used to compute the eigenvectors. The available options are:
564564
565-
arpack : use arnoldi iteration in shift-invert mode.
566-
For this method, M may be a dense matrix, sparse matrix,
567-
or general linear operator.
568-
Warning: ARPACK can be unstable for some problems. It is
569-
best to try several random seeds in order to check results.
565+
- `'auto'` : algorithm will attempt to choose the best method for input
566+
data.
567+
- `'arpack'` : use arnoldi iteration in shift-invert mode. For this
568+
method, M may be a dense matrix, sparse matrix, or general linear
569+
operator.
570+
- `'dense'` : use standard dense matrix operations for the eigenvalue
571+
decomposition. For this method, M must be an array or matrix type.
572+
This method should be avoided for large problems.
570573
571-
dense : use standard dense matrix operations for the eigenvalue
572-
decomposition. For this method, M must be an array
573-
or matrix type. This method should be avoided for
574-
large problems.
574+
.. warning::
575+
ARPACK can be unstable for some problems. It is best to try several
576+
random seeds in order to check results.
575577
576578
tol : float, default=1e-6
577579
Tolerance for 'arpack' method
578580
Not used if eigen_solver=='dense'.
579581
580582
max_iter : int, default=100
581-
maximum number of iterations for the arpack solver.
583+
Maximum number of iterations for the arpack solver.
582584
Not used if eigen_solver=='dense'.
583585
584586
method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'
@@ -594,16 +596,16 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
594596
595597
hessian_tol : float, default=1e-4
596598
Tolerance for Hessian eigenmapping method.
597-
Only used if ``method == 'hessian'``
599+
Only used if ``method == 'hessian'``.
598600
599601
modified_tol : float, default=1e-12
600602
Tolerance for modified LLE method.
601-
Only used if ``method == 'modified'``
603+
Only used if ``method == 'modified'``.
602604
603605
neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, \
604606
default='auto'
605-
algorithm to use for nearest neighbors search,
606-
passed to neighbors.NearestNeighbors instance
607+
Algorithm to use for nearest neighbors search, passed to
608+
:class:`~sklearn.neighbors.NearestNeighbors` instance.
607609
608610
random_state : int, RandomState instance, default=None
609611
Determines the random number generator when
@@ -639,17 +641,11 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
639641
Stores nearest neighbors instance, including BallTree or KDtree
640642
if applicable.
641643
642-
Examples
644+
See Also
643645
--------
644-
>>> from sklearn.datasets import load_digits
645-
>>> from sklearn.manifold import LocallyLinearEmbedding
646-
>>> X, _ = load_digits(return_X_y=True)
647-
>>> X.shape
648-
(1797, 64)
649-
>>> embedding = LocallyLinearEmbedding(n_components=2)
650-
>>> X_transformed = embedding.fit_transform(X[:100])
651-
>>> X_transformed.shape
652-
(100, 2)
646+
SpectralEmbedding : Spectral embedding for non-linear dimensionality
647+
reduction.
648+
TSNE : Distributed Stochastic Neighbor Embedding.
653649
654650
References
655651
----------
@@ -665,6 +661,18 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
665661
.. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear
666662
dimensionality reduction via tangent space alignment.
667663
Journal of Shanghai Univ. 8:406 (2004)
664+
665+
Examples
666+
--------
667+
>>> from sklearn.datasets import load_digits
668+
>>> from sklearn.manifold import LocallyLinearEmbedding
669+
>>> X, _ = load_digits(return_X_y=True)
670+
>>> X.shape
671+
(1797, 64)
672+
>>> embedding = LocallyLinearEmbedding(n_components=2)
673+
>>> X_transformed = embedding.fit_transform(X[:100])
674+
>>> X_transformed.shape
675+
(100, 2)
668676
"""
669677

670678
def __init__(
@@ -722,18 +730,20 @@ def _fit_transform(self, X):
722730
)
723731

724732
def fit(self, X, y=None):
725-
"""Compute the embedding vectors for data X
733+
"""Compute the embedding vectors for data X.
726734
727735
Parameters
728736
----------
729-
X : array-like of shape [n_samples, n_features]
730-
training set.
737+
X : array-like of shape (n_samples, n_features)
738+
Training set.
731739
732740
y : Ignored
741+
Not used, present here for API consistency by convention.
733742
734743
Returns
735744
-------
736-
self : returns an instance of self.
745+
self : object
746+
Fitted `LocallyLinearEmbedding` class instance.
737747
"""
738748
self._fit_transform(X)
739749
return self
@@ -743,14 +753,16 @@ def fit_transform(self, X, y=None):
743753
744754
Parameters
745755
----------
746-
X : array-like of shape [n_samples, n_features]
747-
training set.
756+
X : array-like of shape (n_samples, n_features)
757+
Training set.
748758
749759
y : Ignored
760+
Not used, present here for API consistency by convention.
750761
751762
Returns
752763
-------
753764
X_new : array-like, shape (n_samples, n_components)
765+
Returns the instance itself.
754766
"""
755767
self._fit_transform(X)
756768
return self.embedding_
@@ -762,15 +774,17 @@ def transform(self, X):
762774
Parameters
763775
----------
764776
X : array-like of shape (n_samples, n_features)
777+
Training set.
765778
766779
Returns
767780
-------
768-
X_new : array, shape = [n_samples, n_components]
781+
X_new : ndarray of shape (n_samples, n_components)
782+
Returns the instance itself.
769783
770784
Notes
771785
-----
772786
Because of scaling performed by this method, it is discouraged to use
773-
it together with methods that are not scale-invariant (like SVMs)
787+
it together with methods that are not scale-invariant (like SVMs).
774788
"""
775789
check_is_fitted(self)
776790

0 commit comments

Comments
 (0)