如何解释 k Medoids 输出
How to interpret k Medoids output
我找到了 this K-Medoids 的实现,我决定在我的代码中尝试一下。
我的原始数据集是一个 21x6 矩阵。
要生成我正在使用的距离矩阵:
import scipy.spatial.distance as ssd
distanceMatrix = ssd.squareform(ssd.pdist(matr, 'cosine'))
然后我决定集群的数量:
clusters = int(np.sqrt(len(matr.data)/2))
最后:
clusters, medoids = self.cluster(distanceMatrix,clusters)
print(clusters)
print(medoids)
对于给定的输入,我得到这个输出:
[12 12 12 12 12 12 12 7 7 7 7 11 12 12 12 12 12 12 11 12 12]
[12 7 11]
虽然我期待类似于 sklearn.cluster.KMeans 的输出,但我的矩阵中的每个点都有一个标签。
如果我想使用结果来分散簇元素,我应该如何处理这种输出,如下图(我使用 k-Means 的地方)?
k-medoids 使用数据点作为中心,所以 print(medoids)
会给你输入数据集中的中心索引,print(clusters)
会给你数据点属于哪个组。
图表中的星星将是数据集[12]、数据集[11] 和数据集[7]
我找到了 this K-Medoids 的实现,我决定在我的代码中尝试一下。
我的原始数据集是一个 21x6 矩阵。
要生成我正在使用的距离矩阵:
import scipy.spatial.distance as ssd
distanceMatrix = ssd.squareform(ssd.pdist(matr, 'cosine'))
然后我决定集群的数量:
clusters = int(np.sqrt(len(matr.data)/2))
最后:
clusters, medoids = self.cluster(distanceMatrix,clusters)
print(clusters)
print(medoids)
对于给定的输入,我得到这个输出:
[12 12 12 12 12 12 12 7 7 7 7 11 12 12 12 12 12 12 11 12 12]
[12 7 11]
虽然我期待类似于 sklearn.cluster.KMeans 的输出,但我的矩阵中的每个点都有一个标签。
如果我想使用结果来分散簇元素,我应该如何处理这种输出,如下图(我使用 k-Means 的地方)?
k-medoids 使用数据点作为中心,所以 print(medoids)
会给你输入数据集中的中心索引,print(clusters)
会给你数据点属于哪个组。
图表中的星星将是数据集[12]、数据集[11] 和数据集[7]