Toggle Menu
Prev Up Next

scikit-learn 1.3.2
Other versions

Please cite us if you use the software.

# `sklearn.cluster`.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)

  Spectral Co-Clustering algorithm (Dhillon, 2001).

  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.

  Parameters:
    n_clusters int, 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_vecs int, 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_batch bool, 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_init int, 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_state int, 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.

  Attributes:
    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

      Number of features seen during fit.

      New in version 0.24.

    feature_names_in_ndarray of shape (`n_features_in_`,)

      Names of features seen during fit. Defined only when `X` has feature names that are all strings.

      New in version 1.0.

  See also

  `SpectralBiclustering`

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

  References

  - Dhillon, Inderjit S, 2001. Co-clustering documents and words using bipartite spectral graph partitioning.

  Examples

      >>> 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)

  Methods

  `fit`(X[, y]) | Create a biclustering for X.
  `get_indices`(i) | Row and column indices of the `i`'th bicluster.
  `get_metadata_routing`() | Get metadata routing of this object.
  `get_params`([deep]) | Get parameters for this estimator.
  `get_shape`(i) | Shape of the `i`'th bicluster.
  `get_submatrix`(i, data) | Return the submatrix corresponding to bicluster `i`.
  `set_params`(**params) | Set the parameters of this estimator.

  property biclusters_

    Convenient way to get row and column indicators together.

    Returns the `rows_` and `columns_` members.

  fit(X, y=None)

    Create a biclustering for X.

    Parameters:
      X array-like of shape (n_samples, n_features)

        Training data.

      y Ignored

        Not used, present for API consistency by convention.

    Returns:
      self object

        SpectralBiclustering instance.

  get_indices(i)

    Row and column indices of the `i`’th bicluster.

    Only works if `rows_` and `columns_` attributes exist.

    Parameters:
      i int

        The index of the cluster.

    Returns:
      row_ind ndarray, dtype=np.intp

        Indices of rows in the dataset that belong to the bicluster.

      col_ind ndarray, dtype=np.intp

        Indices of columns in the dataset that belong to the bicluster.

  get_metadata_routing()

    Get metadata routing of this object.

    Please check User Guide on how the routing mechanism works.

    Returns:
      routing MetadataRequest

        A `MetadataRequest` encapsulating routing information.

  get_params(deep=True)

    Get parameters for this estimator.

    Parameters:
      deep bool, default=True

        If True, will return the parameters for this estimator and contained subobjects that are estimators.

    Returns:
      params dict

        Parameter names mapped to their values.

  get_shape(i)

    Shape of the `i`’th bicluster.

    Parameters:
      i int

        The index of the cluster.

    Returns:
      n_rows int

        Number of rows in the bicluster.

      n_cols int

        Number of columns in the bicluster.

  get_submatrix(i, data)

    Return the submatrix corresponding to bicluster `i`.

    Parameters:
      i int

        The index of the cluster.

      data array-like of shape (n_samples, n_features)

        The data.

    Returns:
      submatrix ndarray of shape (n_rows, n_cols)

        The submatrix corresponding to bicluster `i`.

    Notes

    Works with sparse matrices. Only works if `rows_` and `columns_` attributes exist.

  set_params(**params)

    Set the parameters of this estimator.

    The method works on simple estimators as well as on nested objects (such as `Pipeline`). The latter have parameters of the form `<component>__<parameter>` so that it’s possible to update each component of a nested object.

    Parameters:
      **params dict

        Estimator parameters.

    Returns:
      self estimator instance

        Estimator instance.

## Examples using `sklearn.cluster.SpectralCoclustering`

A demo of the Spectral Co-Clustering algorithm

A demo of the Spectral Co-Clustering algorithm

Biclustering documents with the Spectral Co-clustering algorithm

Biclustering documents with the Spectral Co-clustering algorithm