R中的轮廓图


Silhouette plot in R

我有一组数据,其中包括:
项目,关联的簇,轮廓系数。如有必要,我可以使用更多信息进一步扩充此数据集。

我想在R中生成一个轮廓图。我遇到了麻烦,因为遇到的示例都使用内置的kmeans(或相关)聚类函数来绘制结果。我想绕过此步骤并为我自己的聚类算法生成图,但是最后我没有为图函数提供正确的参数。

谢谢。

编辑

数据集示例https://pastebin.mozilla.org/8853427

我尝试过的是加载数据集,并使用基于https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/的各种参数将其传递给plot函数silhouette.html


cluster中的

函数silhouette可以为您做图。它只需要一个集群成员向量(由您选择的任何一种算法生成)和一个不相似矩阵(可能最好使用与生成集群相同的矩阵)。例如:

1
2
3
4
5
6
7
8
library (cluster)
library (vegan)
data(varespec)
dis = vegdist(varespec)
res = pam(dis,3) # or whatever your choice of clustering algorithm is
sil = silhouette (res$clustering,dis) # or use your cluster vector
windows() # RStudio sometimes does not display silhouette plots correctly
plot(sil)

编辑:对于k均值(使用平方的欧几里得距离)

1
2
3
4
5
6
7
8
library (vegan)
library (cluster)
data(varespec)
dis = dist(varespec)^2
res = kmeans(varespec,3)
sil = silhouette (res$cluster, dis)
windows()
plot(sil)