Fork me on GitHub

sklearn.manifold.SpectralEmbedding

class sklearn.manifold.SpectralEmbedding(n_components=2, affinity='nearest_neighbors', gamma=None, random_state=None, eigen_solver=None, n_neighbors=None)

Spectral embedding for non-linear dimensionality reduction.

Forms an affinity matrix given by the specified function and applies spectral decomposition to the corresponding graph laplacian. The resulting transformation is given by the value of the eigenvectors for each data point.

Parameters:

n_components : integer, default: 2

The dimension of the projected subspace.

eigen_solver : {None, ‘arpack’, ‘lobpcg’, or ‘amg’}

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.

random_state : int seed, RandomState instance, or None, default

A pseudo random number generator used for the initialization of the lobpcg eigen vectors decomposition when eigen_solver == ‘amg’.

affinity : string or callable, default

How to construct the affinity matrix.
  • ‘nearest_neighbors’ : construct affinity matrix by knn graph
  • ‘rbf’ : construct affinity matrix by rbf kernel
  • ‘precomputed’ : interpret X as precomputed affinity matrix
  • callable : use passed in function as affinity the function takes in data matrix (n_samples, n_features) and return affinity matrix (n_samples, n_samples).

gamma : float, optional, default

Kernel coefficient for rbf kernel.

n_neighbors : int, default

Number of nearest neighbors for nearest_neighbors graph building.

References

Attributes

embedding_ array, shape = (n_samples, n_components) Spectral embedding of the training matrix.
affinity_matrix_ array, shape = (n_samples, n_samples) Affinity_matrix constructed from samples or precomputed.

Methods

fit(X[, y]) Fit the model from data in X.
fit_transform(X[, y]) Fit the model from data in X and transform X.
get_params([deep]) Get parameters for this estimator.
set_params(**params) Set the parameters of this estimator.
__init__(n_components=2, affinity='nearest_neighbors', gamma=None, random_state=None, eigen_solver=None, n_neighbors=None)
fit(X, y=None)

Fit the model from data in X.

Parameters:

X : array-like, shape (n_samples, n_features)

Training vector, where n_samples in the number of samples and n_features is the number of features.

If affinity is “precomputed” X : array-like, shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.

Returns:

self : object

Returns the instance itself.

fit_transform(X, y=None)

Fit the model from data in X and transform X.

Parameters:

X: array-like, shape (n_samples, n_features) :

Training vector, where n_samples in the number of samples and n_features is the number of features.

If affinity is “precomputed” X : array-like, shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.

Returns:

X_new: array-like, shape (n_samples, n_components) :

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns:self :
Previous
Next