liveBook · Manning

Fviz_nbclust() function

As explained in Statistics Slam Dunk

The fviz_nbclust() function from factoextra computes and visualizes criteria for selecting the number of clusters.

Use factoextra’s fviz_nbclust() to compare possible cluster counts before committing to K-means. It computes and visualizes either within-cluster sum of squares or silhouette criteria. section 11.5.2

The function accepts three practical arguments:

  • data source: the dataset or prepared clustering data. section 11.5.2
  • clustering algorithm: the algorithm used to form candidate clusters, not necessarily K-means. section 11.5.2
  • method: the criterion, such as "wss" for within-cluster sum of squares or "silhouette" for silhouette coefficients. section 11.5.2

Compare payroll-and-wins cluster counts

options(scipen = 000) p3 <- fviz_nbclust(final_kmeans, kmeans, method = "wss") p4 <- fviz_nbclust(final_kmeans, kmeans, method = "silhouette") p3 + p4 + plot_layout(ncol = 1) The resulting plots place candidate cluster counts on the x-axis. The silhouette plot gives a definite optimum, while the WSS scree plot requires judgment; the sharpest WSS drop may suggest two clusters. section 11.5.2

How Statistics Slam Dunk covers it

How deep it goes
Defines three arguments and interprets two diagnostic plots, but stops short of explaining their underlying calculations in detail.
Examples
Uses NBA team payrolls and regular-season wins, comparing WSS and silhouette plots for candidate cluster counts.
What it assumes
Assumes prepared clustering data and familiarity with a clustering algorithm, while defining the function’s three inputs directly.
What you can do after
Apply it via factoextra to compare candidate cluster counts and make a supported choice before fitting the final clustering.
How it connects
Connects K-means clustering with within-cluster sum of squares, silhouette analysis, and patchwork plot composition.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.