gpt4 book ai didi

python - sklearn 谱聚类结果的聚类数量比设置的要少

转载 作者:行者123 更新时间:2023-12-01 07:00:11 25 4
gpt4 key购买 nike

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 均值)可以找到空簇。

例如,将 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

关于python - sklearn 谱聚类结果的聚类数量比设置的要少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58675313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com