BiclusterMixin#

class sklearn.base.BiclusterMixin[source]#

scikit-learn 中所有双聚类估计器的 Mixin 类。

此 Mixin 定义了以下功能:

  • biclusters_ 属性,返回行和列的指示符;

  • get_indices 方法,返回双聚类的行和列索引;

  • get_shape 方法,返回双聚类的形状;

  • get_submatrix 方法,返回与双聚类对应的子矩阵。

示例

>>> import numpy as np
>>> from sklearn.base import BaseEstimator, BiclusterMixin
>>> class DummyBiClustering(BiclusterMixin, BaseEstimator):
...     def fit(self, X, y=None):
...         self.rows_ = np.ones(shape=(1, X.shape[0]), dtype=bool)
...         self.columns_ = np.ones(shape=(1, X.shape[1]), dtype=bool)
...         return self
>>> X = np.array([[1, 1], [2, 1], [1, 0],
...               [4, 7], [3, 5], [3, 6]])
>>> bicluster = DummyBiClustering().fit(X)
>>> hasattr(bicluster, "biclusters_")
True
>>> bicluster.get_indices(0)
(array([0, 1, 2, 3, 4, 5]), array([0, 1]))
get_indices(i)[source]#

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

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

参数:
iint

聚类的索引。

返回:
row_indndarray, dtype=np.intp

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

col_indndarray, dtype=np.intp

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

get_shape(i)[source]#

i 个双聚类的形状。

参数:
iint

聚类的索引。

返回:
n_rowsint

双聚类中的行数。

n_colsint

双聚类中的列数。

get_submatrix(i, data)[source]#

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

参数:
iint

聚类的索引。

data形状为 (n_samples, n_features) 的类数组对象

输入数据。

返回:
submatrix形状为 (n_rows, n_cols) 的 ndarray

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

备注

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