Cluster analysis in R: determine the optimal number of clusters

后端 未结 7 2004
星月不相逢
星月不相逢 2020-11-22 10:28

Being a newbie in R, I\'m not very sure how to choose the best number of clusters to do a k-means analysis. After plotting a subset of below data, how many clusters will be

7条回答
  •  春和景丽
    2020-11-22 10:33

    A simple solution is the library factoextra. You can change the clustering method and the method for calculate the best number of groups. For example if you want to know the best number of clusters for a k- means:

    Data: mtcars

    library(factoextra)   
    fviz_nbclust(mtcars, kmeans, method = "wss") +
          geom_vline(xintercept = 3, linetype = 2)+
          labs(subtitle = "Elbow method")
    

    Finally, we get a graph like:

提交回复
热议问题