BiclusterMixin#

class sklearn.base.BiclusterMixin[source]#

Mixin 類別,用於 scikit-learn 中的所有雙聚類估算器。

此 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]))
屬性 biclusters_#

取得列和行指標的便捷方法。

回傳 rows_columns_ 成員。

get_indices(i)[原始碼]#

i 個雙向分群的列和行索引。

僅在 rows_columns_ 屬性存在時有效。

參數:
iint

分群的索引。

回傳值:
row_indndarray, dtype=np.intp

資料集中屬於該雙向分群的列索引。

col_indndarray, dtype=np.intp

資料集中屬於該雙向分群的行索引。

get_shape(i)[原始碼]#

i 個雙向分群的形狀。

參數:
iint

分群的索引。

回傳值:
n_rowsint

雙向分群中的列數。

n_colsint

雙向分群中的行數。

get_submatrix(i, data)[原始碼]#

回傳對應於雙向分群 i 的子矩陣。

參數:
iint

分群的索引。

data形狀為 (n_samples, n_features) 的類陣列

資料。

回傳值:
submatrix形狀為 (n_rows, n_cols) 的 ndarray

對應於雙向分群 i 的子矩陣。

註記

可處理稀疏矩陣。僅在 rows_columns_ 屬性存在時有效。