Choosing k: Elbow and Silhouette

Inertia always falls as k rises, so it cannot pick one. The silhouette can, and the two often disagree.

Choosing k: Elbow and Silhouette

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

Inertia is the total squared distance from each point to its centroid. It falls at every k and reaches zero at k = n.
The elbow is where the fall stops being steep. It is judged by eye, and frequently there is no clear bend.
The silhouette compares each point's distance to its own cluster against the nearest other one. It has a genuine maximum.
Neither is a substitute for knowing what the clusters are for. k is often decided by the application, not the data.

Overview

Inertia measures how tightly K-means clusters fit their assigned points; the silhouette compares how close each point is to its own cluster versus the nearest alternative. Together they can reveal useful structure, but a metric alone does not define the right grouping.

In this guide
  1. The elbow: inspect inertia
  2. Silhouette: compare within and between clusters
  3. Compare both measures in the visualiser
  4. Make the choice for a purpose

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

  1. Set Data to Three blobs and inspect the inertia and mean silhouette plots across k.
  2. 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.
  3. 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.

Check yourself

0 of 3

Answer without scrolling back up.

  1. Why can inertia alone never choose k?

  2. What does a negative silhouette score for a point mean?

  3. Why does the silhouette have a genuine maximum while inertia does not?

Cheat sheet

Choosing k: Elbow and Silhouette

Run the Elbow method and the Silhouette score on the same dataset. See what each one measures, where they disagree, and how to pick k when they do.

MACHINE LEARNING · vizlearn.in/machine_learning/choosing_k.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.