R:表中的轮廓功能结果

R:表中的轮廓功能结果,r,cluster-analysis,R,Cluster Analysis,有没有办法在显示1)簇的数量和2)每个簇的平均轮廓宽度的表格中接收R中的轮廓函数的结果?轮廓函数返回您需要的所有内容。只要抓住它并以任何你想要的方式总结它。下面是一个使用内置iris数据的示例 library(cluster) Iris_KM3 = kmeans(iris[,1:4],3) SIL = silhouette(Iris_KM3$cluster, dist(iris[,1:4])) aggregate(SIL[,3], list(SIL[,1]), mean) Group.1

有没有办法在显示1)簇的数量和2)每个簇的平均轮廓宽度的表格中接收R中的轮廓函数的结果?

轮廓函数返回您需要的所有内容。只要抓住它并以任何你想要的方式总结它。下面是一个使用内置iris数据的示例

library(cluster)
Iris_KM3 = kmeans(iris[,1:4],3)
SIL = silhouette(Iris_KM3$cluster, dist(iris[,1:4]))

aggregate(SIL[,3], list(SIL[,1]), mean)
  Group.1          x
1       1 0.07624005
2       2 0.49471909
3       3 0.62148628
如果您运行上述代码,请尝试只键入
SIL
str(SIL)
,查看该函数为您提供了什么。

您可以使用
summary()
函数查看用于聚类分析的
剪影()函数的所有详细信息。我将遵循@G5W的答案。您还可以获得每个簇中的观察数

library(cluster)
Iris_KM3 <- kmeans(iris[,1:4],3)
SIL <- silhouette(Iris_KM3$cluster, dist(iris[,1:4]))
summary_SIL <- summary(SIL)
cluster_SIL <- t(rbind(summary_SIL[["clus.sizes"]], summary_SIL[["clus.avg.widths"]]))
colnames(cluster_SIL) <- c("No. of Obs", "Avg. Silh. Width")
库(集群)

Iris_KM3这就是我要找的!非常感谢。