SpectralCoclustering#

class sklearn.cluster.SpectralCoclustering(n_clusters=3, *, svd_method='randomized', n_svd_vecs=None, mini_batch=False, init='k-means++', n_init=10, random_state=None)[source]#

Spectral Co-Clustering algorithm (Dhillon, 2001) [1].

Clusters rows and columns of an array X to solve the relaxed normalized cut of the bipartite graph created from X as follows: the edge between row vertex i and column vertex j has weight X[i, j].

The resulting bicluster structure is block-diagonal, since each row and each column belongs to exactly one bicluster.

Supports sparse matrices, as long as they are nonnegative.

Read more in the User Guide.

参数:
n_clustersint, default=3

The number of biclusters to find.

svd_method{‘randomized’, ‘arpack’}, default=’randomized’

Selects the algorithm for finding singular vectors. May be ‘randomized’ or ‘arpack’. If ‘randomized’, use sklearn.utils.extmath.randomized_svd, which may be faster for large matrices. If ‘arpack’, use scipy.sparse.linalg.svds, which is more accurate, but possibly slower in some cases.

n_svd_vecsint, default=None

Number of vectors to use in calculating the SVD. Corresponds to ncv when svd_method=arpack and n_oversamples when svd_method is ‘randomized`.

mini_batchbool, default=False

Whether to use mini-batch k-means, which is faster but may get different results.

init{‘k-means++’, ‘random’}, or ndarray of shape (n_clusters, n_features), default=’k-means++’

Method for initialization of k-means algorithm; defaults to ‘k-means++’.

n_initint, default=10

Number of random initializations that are tried with the k-means algorithm.

If mini-batch k-means is used, the best initialization is chosen and the algorithm runs once. Otherwise, the algorithm is run for each initialization and the best solution chosen.

random_stateint, RandomState instance, default=None

Used for randomizing the singular value decomposition and the k-means initialization. Use an int to make the randomness deterministic. See Glossary.

属性:
rows_array-like of shape (n_row_clusters, n_rows)

Results of the clustering. rows[i, r] is True if cluster i contains row r. Available only after calling fit.

columns_array-like of shape (n_column_clusters, n_columns)

Results of the clustering, like rows.

row_labels_array-like of shape (n_rows,)

The bicluster label of each row.

column_labels_array-like of shape (n_cols,)

The bicluster label of each column.

biclusters_tuple of two ndarrays

Convenient way to get row and column indicators together.

n_features_in_int

拟合 期间看到的特征数。

0.24 版本新增。

feature_names_in_shape 为 (n_features_in_,) 的 ndarray

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

1.0 版本新增。

另请参阅

SpectralBiclustering

Partitions rows and columns under the assumption that the data has an underlying checkerboard structure.

References

示例

>>> from sklearn.cluster import SpectralCoclustering
>>> import numpy as np
>>> X = np.array([[1, 1], [2, 1], [1, 0],
...               [4, 7], [3, 5], [3, 6]])
>>> clustering = SpectralCoclustering(n_clusters=2, random_state=0).fit(X)
>>> clustering.row_labels_
array([0, 1, 1, 0, 0, 0], dtype=int32)
>>> clustering.column_labels_
array([0, 0], dtype=int32)
>>> clustering
SpectralCoclustering(n_clusters=2, random_state=0)

For a more detailed example, see the following: A demo of the Spectral Co-Clustering algorithm.

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

Create a biclustering for X.

参数:
Xshape 为 (n_samples, n_features) 的 array-like

训练数据。

y被忽略

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

返回:
selfobject

SpectralBiclustering instance.

get_indices(i)[source]#

i 个双聚类的行和列索引。

仅当 rows_columns_ 属性存在时才有效。

参数:
iint

聚类的索引。

返回:
row_indndarray, dtype=np.intp

属于该双聚类的数据集中的行索引。

col_indndarray, dtype=np.intp

属于该双聚类的数据集中的列索引。

get_metadata_routing()[source]#

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

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

返回:
routingMetadataRequest

封装路由信息的 MetadataRequest

get_params(deep=True)[source]#

获取此估计器的参数。

参数:
deepbool, default=True

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

返回:
paramsdict

参数名称映射到其值。

get_shape(i)[source]#

i 个双聚类的形状。

参数:
iint

聚类的索引。

返回:
n_rowsint

双聚类中的行数。

n_colsint

双聚类中的列数。

get_submatrix(i, data)[source]#

返回对应于双聚类 i 的子矩阵。

参数:
iint

聚类的索引。

dataarray-like of shape (n_samples, n_features)

数据。

返回:
submatrixndarray of shape (n_rows, n_cols)

对应于双聚类 i 的子矩阵。

注意事项

适用于稀疏矩阵。仅当 rows_columns_ 属性存在时才有效。

set_params(**params)[source]#

设置此估计器的参数。

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

参数:
**paramsdict

估计器参数。

返回:
selfestimator instance

估计器实例。