https://www.zhihu.com/question/494753171
https://scikit-learn.org.cn/view/391.html
https://zhuanlan.zhihu.com/p/91154535
https://blog.csdn.net/weixin_36474809/article/details/89927502
谱聚类基于相似度矩阵
import numpy as np
from sklearn import datasets
from sklearn.cluster import SpectralClustering
from sklearn import metrics
X, y = datasets.make_blobs(n_samples=512, n_features=6, centers=5, cluster_std=[0.4, 0.3, 0.4, 0.3, 0.4], random_state=11)
affinity_matrix=np.random.rand(512,512)
for i in range(512):
for j in range(512):
if j>i:
affinity_matrix[j,i]=affinity_matrix[i,j]
if j==i:
affinity_matrix[j,i]=1
Cluster=SpectralClustering(n_clusters=32, n_init=10, gamma=1.0, affinity='precomputed', n_neighbors=10, eigen_tol=0.0, assign_labels='kmeans', degree=3,coef0=1)
Cluster=SpectralClustering(n_clusters=32, n_init=10, gamma=1.0, affinity='rbf', n_neighbors=10, eigen_tol=0.0, assign_labels='kmeans', degree=3,coef0=1)
# y_pred = Cluster.fit_predict(affinity_matrix)
y_pred = Cluster.fit_predict(X)
Cluster.affinity_matrix_
Cluster.labels_
# print("Calinski-Harabasz Score", metrics.calinski_harabaz_score(X, y_pred) )
ref
https://blog.csdn.net/qq_45448654/article/details/121013471