Exercise

K-means: Elbow analysis

In the previous exercises you used the dendrogram to propose a clustering that generated 3 trees. In this exercise you will leverage the k-means elbow plot to propose the "best" number of clusters.

Instructions

100 XP
  • Use map_dbl() to run kmeans() using the oes data for k values ranging from 1 to 10 and extract the total within-cluster sum of squares value from each model: model$tot.withinss. Store the resulting vector as tot_withinss.
  • Build a new data frame elbow_df containing the values of k and the vector of total within-cluster sum of squares.
  • Use the values in elbow_df to plot a line plot showing the relationship between k and total within-cluster sum of squares.