The elbow: inspect inertia
Inertia is the sum of squared distances from each point to its assigned centroid. It cannot select k by its minimum: adding clusters can only reduce inertia, and at k equal to the number of points it reaches zero. The elbow method looks for a bend where the improvement begins to slow.
The bend can be subjective or absent. A smooth curve does not contain a hidden, objectively correct elbow. Use it as a clue and compare the resulting clusters with the task.
Silhouette: compare within and between clusters
For one point, let a be its average distance to points in its own cluster, and b its average distance to points in the nearest other cluster. Its silhouette is:
s = (b − a) / max(a, b)
The value lies between −1 and 1. Near +1 means the point is much closer to its own cluster; near 0 means it is near a boundary; below 0 means it may fit another cluster better. Average the point scores to compare candidate values of k. Silhouette favours compact, well-separated groups and can undervalue non-convex shapes; it is not a universal quality score.
Compare both measures in the visualiser
- Set Data to Three blobs and inspect the inertia and mean silhouette plots across k.
- Change Data to Two crescents. K-means still creates centroid-based groups, so the metrics may prefer a split that does not match the curved shapes.
- Adjust Blob spread and watch whether the evidence for a single k becomes weaker as groups overlap.
The visualiser shows why metric disagreement can be informative: it may reveal ambiguous structure or a mismatch between the clustering method and the data.
Make the choice for a purpose
Choose k based on how the clusters will be used. If a team needs a manageable number of segments, a slightly lower silhouette may be acceptable. If the goal is to recover known labels, compare cluster assignments with those labels using an appropriate external measure. If the data has curved groups or different densities, try a method such as DBSCAN or hierarchical clustering rather than forcing K-means to fit it.
Run K-means with multiple initialisations and compare stable solutions. The scikit-learn clustering guide documents silhouette scoring and its assumptions. Continue with K-means for the clustering procedure itself.