How do you choose the number of clusters k for k-means, and why can't you just pick the k that minimises the k-means objective?

Unsupervised learning, Clustering
Level L1 Beginner. Length Short. Nature Th Theoretical.

What's being asked

Whether you know that the within-cluster spread always falls as k grows, and the usual ways of choosing k.

Key idea

The k-means objective W(k)=∑i∥xi−μci∥2, where μci is the centre of the cluster that point xi belongs to, never increases with k and reaches 0 at k=n. Minimising it would always pick k=n, one cluster per point. So use a criterion that also rewards simplicity or separation: the elbow of W(k), the average silhouette, the gap statistic, or BIC for a Gaussian mixture.

Steps

  1. Explain why W(k) cannot be the criterion. With more centres the best clustering can only get tighter, and with k=n every point is its own centre, so W(n)=0.
  2. Elbow method: plot W(k) against k and pick the k after which the curve flattens, where extra clusters stop helping much.
  3. Silhouette: for each point, s=b−amax⁡(a,b), where a is its mean distance to its own cluster and b to the nearest other cluster. Pick the k with the highest average s.
  4. Gap statistic, which compares log⁡W(k) with its value on random uniform data; or BIC for a Gaussian mixture model, which adds a penalty for the number of parameters.
  5. Mention the practical side: often k is set by how many groups the business can actually act on.

Common mistakes

How long your answer should be

4–6 sentences.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: Why should you usually standardise features before running principal component analysis (PCA)?
Next in Unsupervised learning: Why is k-medoids (PAM) more robust to outliers than k-means, and what does it cost you?