spectral_embedding
- sklearn.manifold.spectral_embedding(adjacency, *, n_components=8, eigen_solver=None, random_state=None, eigen_tol='auto', norm_laplacian=True, drop_first=
Project the sample on the first eigenvectors of the graph Laplacian.
The adjacency matrix is used to compute a normalized graph Laplacian whose spectrum (especially the eigenvectors associated to the smallest eigenvalues) has an interpretation in terms of minimal number of cuts necessary to split the graph into comparably sized components.
This embedding can also ‘work’ even if the adjacency variable is
not strictly the adjacency matrix of a graph but more generally
an affinity or similarity matrix between samples (for instance the
heat kernel of a euclidean distance matrix or a k-NN matrix).
However care must taken to always make the affinity matrix symmetric so that the eigenvector decomposition works as expected.
Note : Laplacian Eigenmaps is the actual algorithm implemented here.
Read more in the User Guide.
The adjacency matrix of the graph to embed.
The dimension of the projection subspace.
The eigenvalue decomposition strategy to use. AMG requires pyamg
to be installed. It can be faster on very large, sparse problems,
but may also lead to instabilities. If None, then 'arpack' is
used.
A pseudo random number generator used for the initialization
of the lobpcg eigen vectors decomposition when eigen_solver ==
'amg', and for the K-Means initialization. Use an int to make
the results deterministic across calls (See
Glossary).
Stopping criterion for eigendecomposition of the Laplacian matrix.
If eigen_tol="auto" then the passed tolerance will depend on the
eigen_solver:
If True, then compute symmetric normalized Laplacian.
Whether to drop the first eigenvector. For spectral embedding, this should be True as the first eigenvector should be constant vector for connected graph, but for spectral clustering, this should be kept as False to retain the first eigenvector.
The reduced samples.
Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph has one connected component. If there graph has many components, the first few eigenvectors will simply uncover the connected components of the graph.
>>> from sklearn.datasets import load_digits
>>> from sklearn.neighbors import kneighbors_graph
>>> from sklearn.manifold import spectral_embedding
>>> X, _ = load_digits(return_X_y=True)
>>> X = X[:100
Note that when using eigen_solver="amg" values of tol<1e-5 may lead
to convergence issues and should be avoided.