【问题标题】:how to print the optimal number of clusters using fviz_nbclust如何使用 fviz_nbclust 打印最佳簇数
【发布时间】:2017-04-10 20:02:02
【问题描述】:

我需要帮助来了解如何使用 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)

我得到了剧情,但我还是不知道如何找到数字?

谢谢

My plot is in this link to show the rlation between wss and number of clusters with no information about the optimal number of clusters

【问题讨论】:

标签: r cluster-analysis k-means factoextra


【解决方案1】:
n_clust<-fviz_nbclust(df, kmeans, method = "silhouette",k.max = 30)
n_clust<-n_clust$data
max_cluster<-as.numeric(n_clust$clusters[which.max(n_clust$y)])

【讨论】:

  • 您应该在答案中添加描述以改进它。
  • 请在您的代码中添加一些解释,以便其他人可以从中学习
【解决方案2】:

“肘部”没有可靠的数学定义(因为 x 和 y 上有不同的比例,所以没有角度),在像你这样的图中可能根本没有“肘部”。

很可能,k-means 不适用于任何 k。这种情况经常发生。例如,如果您的数据不包含集群。

尝试生成统一的数据,并绘制相同的图 - 它看起来很相似。

【讨论】:

  • 那么您认为使用 k-means 不会产生有意义的集群吗?
  • 如果曲线看起来像这样就不行。绘制 5000/k 作为比较。
猜你喜欢
  • 2020-06-28
  • 2019-10-26
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
  • 1970-01-01
  • 2016-03-16
  • 2019-04-09
  • 2015-12-10
相关资源
最近更新 更多