Spectral Clustering#

Note

Spectral Clustering takes a similarity matrix between the instances and create a low dimensional embedding from it (i.e. it reduces its dimensionality), then it uses another clustering algorithm in the low-dimensional space (e.g. K-means). Spectral clustering can capture comlplex cluster structure, and it also be used to cut graphs.

使用方法#

import numpy as np

# (n_samples, n_features)
X = np.array([[1, 1], [2, 1], [1, 0],
              [4, 7], [3, 5], [3, 6]])
from sklearn.cluster import SpectralClustering

clustering = SpectralClustering(n_clusters=2,
        assign_labels='discretize',
        random_state=0).fit(X)
clustering.labels_
array([1, 1, 1, 0, 0, 0])