我需要帮助来了解如何使用 R 中的 k-means 集群找到最佳的集群数量。
我的代码是
library(cluster)
library(factoextra)
#read data
data<-read.csv("..\file.txt",header=FALSE, sep=" ")
#determine number of clusters to use
k.max<- 22
wss <- sapply(2:k.max, function(k){kmeans(data, k, nstart=10 )$tot.withinss})
print(wss)
plot(2:k.max, wss, type="b", pch = 19, xlab="Number of clusters K", ylab="Total within-clusters sum of squares")
fviz_nbclust(data, kmeans, method = "wss") + geom_vline(xintercept = 3, linetype = 2)
我得到了情节,但我仍然不知道如何找到数字?
谢谢