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
Xto solve the relaxed normalized cut of the bipartite graph created fromXas follows: the edge between row vertexiand column vertexjhas weightX[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’, usescipy.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
ncvwhensvd_method=arpackandn_oversampleswhensvd_methodis ‘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 clustericontains rowr. Available only after callingfit.- 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 ndarraysConvenient 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 版本新增。
另请参阅
SpectralBiclusteringPartitions 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
参数名称映射到其值。