Jack Armstrong
Jack Armstrong

Reputation: 1249

Visualize Results from NbClust

Upon performing NbClust on my data, I found that 5 clusters were determined to be the optimal number according to the majority rule. However, how do I find out which indices produced those 5 clusters?

Also how do I plot this new data and color/group with elipsis? In the past I have used fviz_cluster from the facto package, but usually with a kmeans object. I tried to input my nb but that is a list and hence results in an error. I know I can plot a histogram with the optimal number of clusters, but I am not trying to plot that.

Reproducible Example with iris as an example

library("NbClust")
data(iris)
iris.scaled <- scale(iris[, -5])
set.seed(123)
res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete", index ="gap") 
res.nb # print the results
fviz_nbclust(res.nb) + theme_minimal()

Upvotes: 0

Views: 2191

Answers (1)

bbiasi
bbiasi

Reputation: 1599

The argument index should be all. However it is possible to let the package itself do this by neglecting to fill in this argument.

res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete")

res.nb <- NbClust(iris.scaled, distance = "euclidean",
                  min.nc = 2, max.nc = 10, 
                  method = "complete", 
                  index ="all") 
library(factoextra)
fviz_nbclust(res.nb)

enter image description here

Upvotes: 2

Related Questions