Thursday, December 3, 2026 | London 11°C · Drizzle
DailyGlimpse

AI

Finding the Sweet Spot for Centroids in K-Means Clustering

Data Science With Dennis 1 min read

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.

  1. Run k-means for a range of cluster numbers (e.g., 1 to 10).
  2. For each value, compute the within-cluster sum of squares (WCSS), which measures how compact the clusters are.
  3. 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.
  4. 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.

React