SpectralEmbedding#

class sklearn.manifold.SpectralEmbedding(n_components=2, *, affinity='nearest_neighbors', gamma=None, random_state=None, eigen_solver=None, eigen_tol='auto', n_neighbors=None, n_jobs=None)[source]#

用于非线性降维的谱嵌入。

根据指定的函数形成一个亲和矩阵,并对相应的图拉普拉斯算子应用谱分解。得到的变换由每个数据点的特征向量值给出。

注:拉普拉斯特征图(Laplacian Eigenmaps)是此处实现的实际算法。

用户指南中阅读更多内容。

参数:
n_componentsint, default=2

投影子空间的维度。

affinity{‘nearest_neighbors’, ‘rbf’, ‘precomputed’, ‘precomputed_nearest_neighbors’} 或 callable, default=’nearest_neighbors’
如何构建亲和矩阵。
  • ‘nearest_neighbors’:通过计算最近邻图来构建亲和矩阵。

  • ‘rbf’:通过计算径向基函数(RBF)核来构建亲和矩阵。

  • ‘precomputed’:将X解释为预计算的亲和矩阵。

  • ‘precomputed_nearest_neighbors’:将X解释为预计算最近邻的稀疏图,并通过选择n_neighbors个最近邻来构建亲和矩阵。

  • callable:使用传入的函数作为亲和函数,该函数接受数据矩阵(n_samples, n_features)并返回亲和矩阵(n_samples, n_samples)。

gammafloat, default=None

RBF核的核系数。如果为None,gamma将被设置为1/n_features。

random_stateint, RandomState instance or None, default=None

eigen_solver == 'amg'时,用于初始化lobpcg特征向量分解的伪随机数生成器,以及用于K-Means初始化。使用整数可以使结果在不同调用中具有确定性(参见词汇表)。

注意

用于初始化 lobpcg 特征向量分解的伪随机数生成器,当 eigen_solver == 'amg' 时,以及用于 K-Means 初始化。使用整数使结果在多次调用中具有确定性(请参阅 词汇表)。

要形成的聚类数。

要使用的特征值分解策略。AMG需要安装pyamg。它在非常大、稀疏的问题上可能更快。如果为None,则使用'arpack'

使用最近邻方法构造亲和力矩阵时要使用的邻居数。对于 affinity='rbf',将被忽略。

Stopping criterion for eigendecomposition of the Laplacian matrix. If eigen_tol="auto" then the passed tolerance will depend on the eigen_solver

  • 拉普拉斯矩阵特征分解的停止准则。如果 eigen_tol="auto",则传递的容差将取决于 eigen_solver

  • 如果 eigen_solver="arpack",则 eigen_tol=0.0

如果 eigen_solver="lobpcg"eigen_solver="amg",则 eigen_tol=None,它将配置底层 lobpcg 求解器根据其启发式方法自动解析值。有关详细信息,请参阅 scipy.sparse.linalg.lobpcg

1.2 版本新增。

n_neighborsint, default=None

用于nearest_neighbors图构建的最近邻居数量。如果为None,n_neighbors将被设置为max(n_samples/10, 1)。

n_jobsint, default=None

The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.

属性:
embedding_形状为 (n_samples, n_components) 的 ndarray

训练矩阵的谱嵌入。

affinity_matrix_shape (n_samples, n_samples) 的 ndarray

从样本构建或预计算的亲和矩阵。

n_features_in_int

拟合 期间看到的特征数。

0.24 版本新增。

feature_names_in_shape 为 (n_features_in_,) 的 ndarray

fit 期间看到的特征名称。仅当 X 具有全部为字符串的特征名称时才定义。

1.0 版本新增。

n_neighbors_int

实际使用的最近邻居数量。

另请参阅

Isomap

通过等距映射进行的非线性降维。

References

示例

>>> from sklearn.datasets import load_digits
>>> from sklearn.manifold import SpectralEmbedding
>>> X, _ = load_digits(return_X_y=True)
>>> X.shape
(1797, 64)
>>> embedding = SpectralEmbedding(n_components=2)
>>> X_transformed = embedding.fit_transform(X[:100])
>>> X_transformed.shape
(100, 2)
fit(X, y=None)[source]#

根据 X 中的数据拟合模型。

参数:
Xshape 为 (n_samples, n_features) 的 {array-like, sparse matrix}

训练向量,其中 n_samples 是样本数,n_features 是特征数。

如果affinity是“precomputed”,则X:{类数组, 稀疏矩阵},shape (n_samples, n_samples),将X解释为从样本计算的预计算邻接图。

y被忽略

未使用,按照惯例为保持 API 一致性而存在。

返回:
selfobject

返回实例本身。

fit_transform(X, y=None)[source]#

从 X 中的数据拟合模型并转换 X。

参数:
Xshape 为 (n_samples, n_features) 的 {array-like, sparse matrix}

训练向量,其中 n_samples 是样本数,n_features 是特征数。

如果affinity是“precomputed”,则X:shape (n_samples, n_samples) 的 {类数组, 稀疏矩阵},将X解释为从样本计算的预计算邻接图。

y被忽略

未使用,按照惯例为保持 API 一致性而存在。

返回:
X_newshape (n_samples, n_components) 的类数组

训练矩阵的谱嵌入。

get_metadata_routing()[source]#

获取此对象的元数据路由。

请查阅 用户指南,了解路由机制如何工作。

返回:
routingMetadataRequest

封装路由信息的 MetadataRequest

get_params(deep=True)[source]#

获取此估计器的参数。

参数:
deepbool, default=True

如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。

返回:
paramsdict

参数名称映射到其值。

set_params(**params)[source]#

设置此估计器的参数。

此方法适用于简单的估计器以及嵌套对象(如 Pipeline)。后者具有 <component>__<parameter> 形式的参数,以便可以更新嵌套对象的每个组件。

参数:
**paramsdict

估计器参数。

返回:
selfestimator instance

估计器实例。