factoextra icon indicating copy to clipboard operation
factoextra copied to clipboard

Problem with fviz_nbclust()

Open turexx opened this issue 2 years ago • 3 comments

I'm doing a report for a data analysis and statistical learning subject. The problem is in the clustering phase. I have to find the optimal number of clusters, and i already done. But when i try to display the graph with the following function it gives me an error:

nb<-NbClust(df, diss=NULL,distance="euclidean",method="average")

fviz_nbclust(nb) Error in if (class(best_nc) == "numeric") print(best_nc) else if (class(best_nc) == : the condition has length > 1

df is the standardized data set with only numerical data. The error is referred to the fviz_nbclust function. I'd like to know what to do. I have already try to reinstall the packages, RStudio, everything but nothing. I also did, inside the NbClust() function the min_nc or max_nc and stuff like that.

Thanks for your help.

turexx avatar May 01 '22 12:05 turexx

Exactly the same...

Thanks for your help

johann-DP avatar Jan 24 '23 17:01 johann-DP

Same here too. Class(best_nc) from NbClust object return a list("matrix","array") of length of 2. The conditions (class(best_nc) == "numeric") and (class(best_nc)== "matrix") can be changed into (class(best_nc)[1] == "numeric") and (class(best_nc)[1] == "matrix") , in the fviz_nbclust function, . The graph output does not have the number of cluster sorted. One can add as.numeric in df <- data.frame(Number_clusters = as.numeric(names(ss)), freq = ss, stringsAsFactors = TRUE ) to sort them, in the .viz_NbClust function.

charlie068 avatar May 31 '23 13:05 charlie068

See here for fix posted on StackOverflow -

https://stackoverflow.com/questions/72075707/rstudio-error-with-the-fviz-nbclust-function

BuddahKat avatar Jun 20 '23 16:06 BuddahKat