sklearn 谱聚类导致聚类数量少于集合
sklearn spectral clustering results in smaller number of cluster than set
from sklearn.cluster import SpectralClustering
import numpy as np
test = np.array([[63.15907836],
[69.67386298],
[67.20030411],
[66.25165771],
[62.21031327],
[55.09531565],
[65.85034014],
[52.99841912],
[52.04523986],
[52.09008007],
[94.65364516]])
clustering = SpectralClustering(n_clusters = 4).fit(test)
clustering.labels_
上面的代码结果是array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1], dtype=int32)
,这让我很惊讶。谱聚类需要设置多个簇,我这样做了,但只得到两个簇。我错过了什么?
有时,根据初始化,谱聚类(和 k-means)可以找到空聚类。
例如,将 random_state
设置为 17 会导致 4 个集群:
clustering = SpectralClustering(n_clusters = 4, random_state=17).fit(test)
您可以在 k-means 中找到它的说明(谱聚类依赖于 k-means):http://user.ceng.metu.edu.tr/~tcan/ceng465_f1314/Schedule/KMeansEmpty.html
from sklearn.cluster import SpectralClustering
import numpy as np
test = np.array([[63.15907836],
[69.67386298],
[67.20030411],
[66.25165771],
[62.21031327],
[55.09531565],
[65.85034014],
[52.99841912],
[52.04523986],
[52.09008007],
[94.65364516]])
clustering = SpectralClustering(n_clusters = 4).fit(test)
clustering.labels_
上面的代码结果是array([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1], dtype=int32)
,这让我很惊讶。谱聚类需要设置多个簇,我这样做了,但只得到两个簇。我错过了什么?
有时,根据初始化,谱聚类(和 k-means)可以找到空聚类。
例如,将 random_state
设置为 17 会导致 4 个集群:
clustering = SpectralClustering(n_clusters = 4, random_state=17).fit(test)
您可以在 k-means 中找到它的说明(谱聚类依赖于 k-means):http://user.ceng.metu.edu.tr/~tcan/ceng465_f1314/Schedule/KMeansEmpty.html