Choosing the right number of clusters (centroids) is a common challenge in k-means clustering. A popular technique to address this is the elbow method.
- Run k-means for a range of cluster numbers (e.g., 1 to 10).
- For each value, compute the within-cluster sum of squares (WCSS), which measures how compact the clusters are.
- Plot the WCSS against the number of clusters. As clusters increase, WCSS decreases, but at some point the improvement levels off—forming an "elbow" in the graph.
- The optimal number of clusters is typically at the elbow, where adding more clusters yields diminishing returns.
For example, if the elbow appears at k=3, that’s a good choice. This method provides a visual and intuitive way to balance complexity and fit.