[英]R: Silhouette function results in table
有沒有辦法在表中接收 R 中輪廓函數的結果,該表顯示 1)簇的數量和 2)每個簇的平均輪廓寬度?
你需要的一切都由剪影函數返回。 只需捕捉它並以您想要的任何方式對其進行總結。 這是使用內置虹膜數據的示例。
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()
函數查看用於聚類分析的silhouette()
函數的所有詳細信息。 我將遵循@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")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.