@@ -543,42 +543,44 @@ def locally_linear_embedding(
543
543
544
544
545
545
class LocallyLinearEmbedding (TransformerMixin , _UnstableArchMixin , BaseEstimator ):
546
- """Locally Linear Embedding
546
+ """Locally Linear Embedding.
547
547
548
548
Read more in the :ref:`User Guide <locally_linear_embedding>`.
549
549
550
550
Parameters
551
551
----------
552
552
n_neighbors : int, default=5
553
- number of neighbors to consider for each point.
553
+ Number of neighbors to consider for each point.
554
554
555
555
n_components : int, default=2
556
- number of coordinates for the manifold
556
+ Number of coordinates for the manifold.
557
557
558
558
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
560
560
matrix of the distances.
561
561
562
562
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:
564
564
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.
570
573
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.
575
577
576
578
tol : float, default=1e-6
577
579
Tolerance for 'arpack' method
578
580
Not used if eigen_solver=='dense'.
579
581
580
582
max_iter : int, default=100
581
- maximum number of iterations for the arpack solver.
583
+ Maximum number of iterations for the arpack solver.
582
584
Not used if eigen_solver=='dense'.
583
585
584
586
method : {'standard', 'hessian', 'modified', 'ltsa'}, default='standard'
@@ -594,16 +596,16 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
594
596
595
597
hessian_tol : float, default=1e-4
596
598
Tolerance for Hessian eigenmapping method.
597
- Only used if ``method == 'hessian'``
599
+ Only used if ``method == 'hessian'``.
598
600
599
601
modified_tol : float, default=1e-12
600
602
Tolerance for modified LLE method.
601
- Only used if ``method == 'modified'``
603
+ Only used if ``method == 'modified'``.
602
604
603
605
neighbors_algorithm : {'auto', 'brute', 'kd_tree', 'ball_tree'}, \
604
606
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.
607
609
608
610
random_state : int, RandomState instance, default=None
609
611
Determines the random number generator when
@@ -639,17 +641,11 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
639
641
Stores nearest neighbors instance, including BallTree or KDtree
640
642
if applicable.
641
643
642
- Examples
644
+ See Also
643
645
--------
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.
653
649
654
650
References
655
651
----------
@@ -665,6 +661,18 @@ class LocallyLinearEmbedding(TransformerMixin, _UnstableArchMixin, BaseEstimator
665
661
.. [4] Zhang, Z. & Zha, H. Principal manifolds and nonlinear
666
662
dimensionality reduction via tangent space alignment.
667
663
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)
668
676
"""
669
677
670
678
def __init__ (
@@ -722,18 +730,20 @@ def _fit_transform(self, X):
722
730
)
723
731
724
732
def fit (self , X , y = None ):
725
- """Compute the embedding vectors for data X
733
+ """Compute the embedding vectors for data X.
726
734
727
735
Parameters
728
736
----------
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.
731
739
732
740
y : Ignored
741
+ Not used, present here for API consistency by convention.
733
742
734
743
Returns
735
744
-------
736
- self : returns an instance of self.
745
+ self : object
746
+ Fitted `LocallyLinearEmbedding` class instance.
737
747
"""
738
748
self ._fit_transform (X )
739
749
return self
@@ -743,14 +753,16 @@ def fit_transform(self, X, y=None):
743
753
744
754
Parameters
745
755
----------
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.
748
758
749
759
y : Ignored
760
+ Not used, present here for API consistency by convention.
750
761
751
762
Returns
752
763
-------
753
764
X_new : array-like, shape (n_samples, n_components)
765
+ Returns the instance itself.
754
766
"""
755
767
self ._fit_transform (X )
756
768
return self .embedding_
@@ -762,15 +774,17 @@ def transform(self, X):
762
774
Parameters
763
775
----------
764
776
X : array-like of shape (n_samples, n_features)
777
+ Training set.
765
778
766
779
Returns
767
780
-------
768
- X_new : array, shape = [n_samples, n_components]
781
+ X_new : ndarray of shape (n_samples, n_components)
782
+ Returns the instance itself.
769
783
770
784
Notes
771
785
-----
772
786
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).
774
788
"""
775
789
check_is_fitted (self )
776
790
0 commit comments