聚类方法学习(五)谱聚类算法Spectral Clustering与案例

谱聚类算法概述

详情请参考:https://www.cnblogs.com/pinard/p/6221564.html

Spectral Clustering算例

from sklearn.cluster import spectral_clustering
import numpy as np
from sklearn import metrics

from sklearn.preprocessing import StandardScaler

X = np.random.random((1000, 4))
X = StandardScaler().fit_transform(X)
metrics_metrix = (-1 * metrics.pairwise.pairwise_distances(X)).astype(np.int32)
metrics_metrix += -1 * metrics_metrix.min()
lables = spectral_clustering(metrics_metrix, n_clusters=4)  # 得到聚类结果

绘图:

import matplotlib.pyplot as plt

plt.scatter(X[:, 0], X[:, 1], c=lables)
plt.show()

你可能感兴趣的:(数据处理,聚类)