Clustering, and What the Objective Assumes
How k-means alternates assignment and update until the labels settle, why a converged solution can be far from the best one and how restarts detect that, what a within-cluster sum of squares curve does and does not tell you about the number of groups, and the case that matters most: concentric rings, where the ring grouping scores worse on the objective than the partition the method returns, so the failure lies in what the objective treats as a cluster rather than in the algorithm.
Definition
Clustering partitions observations into groups without using any response variable. There is no supervised prediction target, so there is no held-out prediction error of the kind used in regression and classification. Other external checks remain available, including stability under resampling, likelihood-based criteria for model-based clustering, and validation against labels held back for the purpose; what the algorithm itself optimises is a stated criterion that a partition satisfies well or does not.
k-means fixes the number of groups
where
- Assignment. Put each point in the group whose centroid is nearest.
- Update. Move each centroid to the mean of the points now assigned to it.
Each step can only lower the objective or leave it unchanged, and the number of possible assignments is finite, so the algorithm terminates. It terminates at a partition where no single point lowers the objective by changing clusters and every centroid is at its members' mean. A local optimum, which need not be the global one.
What the objective assumes. Minimising squared distance to a centre treats a cluster as a roughly round region around a point. Nothing in the algorithm can override this, because it is the criterion rather than a detail of the search.
Assumptions and scope
The WCSS objective treats a cluster as a region of small squared distance to a centre, which makes it suited to roughly spherical groups of comparable spread and unsuited to elongated, nested, or otherwise non-convex structure. This is a property of the criterion, not of the search, so no number of restarts changes it.
The algorithm converges to a local optimum. Convergence means no point improves the objective by moving alone and every centroid is at its members' mean; it carries no guarantee of global optimality. Multiple restarts compared by objective value reduce sensitivity to initialisation and can find a better solution than any single run, which is what makes a reported result defensible. They do not establish that the global optimum was reached, which would require exhaustive or global optimisation.
is an input, not an output. A WCSS curve falls monotonically in by construction, because more groups can always fit the data more closely, so the curve alone cannot identify a cluster count, and on data with no separated groups the successive drops decay smoothly with no value to select. Squared Euclidean distance makes the objective scale-dependent: multiplying one coordinate by a constant changes which partition minimises WCSS. Standardising is a decision about how much each variable should count, and it is made before clustering rather than discovered by it.
The worked figures come from exact arithmetic on the small datasets stated in the blocks, with the optimal partitions verified by exhaustive enumeration over all assignments rather than by trusting the algorithm's own output.
Worked material
Example
Four datasets and what the objective says about each
Four well-separated groups,
| WCSS | drop | |
|---|---|---|
| 1 | — | |
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 |
The drop at
One elongated blob, no
No cliff. The reductions decay smoothly, and the last one is larger than the one before it, so the sequence is not even monotone. The curve identifies no number of groups, because there are none to identify. A reader determined to find an elbow could point at
Two concentric rings, where the criterion favours a different partition. Twelve points at radius
The method is not failing to find the rings. It is rejecting them, correctly, under the criterion it was given.
The same rings under a different criterion. Single linkage merges the two groups whose nearest members are closest. Applied to the same thirty-six points with
---
The first is the case the elbow method is sold on, and it works. The second shows the same plot produced from data with no structure, which is why the plot alone is not evidence. The third shows the objective preferring an answer the analyst does not want, which no amount of computation will overturn. The fourth shows that the disagreement was never about the data. Two criteria, two different right answers.
Contrast
Pairs that differ in one respect
A bad search against a bad criterion.
| nine points, run 2 | concentric rings | |
|---|---|---|
| returned WCSS | ||
| intended partition's WCSS | ||
| intended answer scores | better | worse |
| diagnosis | search stopped early | criterion rejects it |
| fix | restarts | different criterion |
Both look identical from the outside: a result that disagrees with what you expected. The single computation that separates them is the objective value of the partition you wanted. If it beats what was returned, the search failed. If it loses, the search succeeded and the criterion is the thing that does not match.
The two failures have opposite remedies, and restarts address only the first.
A sharp elbow against a smooth decay.
Four separated groups: drops of
Both curves fall monotonically; both can be plotted and pointed at. Only the first contains a discontinuity, and it is the discontinuity rather than the downward slope that carries the information. Note that the blob's first drop,
k-means against single linkage, on identical data.
The thirty-six ring points,
Neither is the true clustering. What single linkage gains in recovering elongated structure it pays for in fragility: a single point between the rings would chain them into one cluster, which is a failure mode k-means does not have. Neither method dominates.
Convergence against optimality.
Run 1 and run 2 on the nine points both satisfy the stopping condition exactly. No point improves alone, every centroid at its members' mean. One scores
A number of groups the data supports, against a number you supplied.
k-means with
Common errors
Common misconception
That once k-means stops changing its labels it has found the best partition, so a single run settles the question. Convergence only means no single point lowers the objective by changing clusters and every centroid is at its members' mean; it says nothing about whether another partition scores better. On the nine-point dataset of this unit, two nearby groups of three on the left and one distant group of three on the right, the optimal three-cluster partition has within-cluster sum of squares
Common misconception
That a dataset has a true number of clusters and a true grouping, which a good method finds and a bad one misses. A clustering method returns the partition that best satisfies a stated criterion, and different criteria have different best answers on the same data. On the two concentric rings of this unit, twelve points at radius
Related units
Requires
Connected
- Estimating Out-of-Sample Error (contrasts with)
- Trees and Ensembles of Them (related)