Skip to content
AI.info

Unsupervised learning

K-Means Initialization, K Selection, and Failure Modes

Use K-Means++ and repeated starts, evaluate candidate K values, and recognize instability, imbalance, and outlier-driven partitions.

By the end you can

Example

Failure signatures in real K-Means runs

The labels alone hide several diagnostic patterns. Each of the following is visible in the output of a single fit, and none of them shows up in the inertia number that usually gets reported alongside it.

  • Singleton cluster: One extreme observation receives its own centroid, signalling outlier sensitivity or an overly large K.
  • Empty update: A centroid loses every assignment and must be reinitialized according to the implementation policy.
  • Size imbalance: One broad population is split repeatedly while a small meaningful group is absorbed into a nearby centroid.
  • Seed disagreement: Similar inertia values correspond to different assignments, showing that the objective has competing solutions the summary number cannot distinguish.
  • Boundary churn: Points switch clusters across refits despite minimal change in their features, making any intervention keyed to cluster membership inconsistent.

Key idea

A sharp elbow can be manufactured by preprocessing

Feature scaling, duplicate rows, outliers and block weighting can each create or erase a bend in the inertia curve. Report the elbow without those choices and the selection looks more objective than it is. The dependence is not a matter of taste. SSE is a squared quantity, and in 2023 Erich Schubert spelled out the consequence: “If we scale the entire data set by a factor of α, the SSE will change by α2, and the “optimum” found by most of the geometric methods changes, while it is clear that it should not.” Rescale everything by α, multiply SSE by α², and the answer moves. Nothing about the data has changed.

Schubert then counted the damage. He ran eight elbow-detection heuristics — Jump, L-Method, iterative L-Method, Kneedle, Curvature, PyClustering, Shi angles and AutoElbow — on five toy data sets. One of the five is uniform noise. It contains no clusters at all, so its true k is 1. Every one of the eight returned between 4 and 6 clusters. On the set of many blobs, whose true k is 25, they returned between 3 and 38. His table carries the row “true k 3 3 25 1 1”, and the sentence beside it is blunt: “For the data set with many clusters as well as the uniform data set, all the elbow-based methods failed.”

Plot several diagnostics and inspect the actual memberships. A curve is evidence about one representation, at one scaling. It is not a census of the groups in the data.

Every K-selection plot inherits the feature space that produced it.

Restart disagreement is a property of the objective, not of the software

Run K-Means five times on the same matrix and you can get several different partitions at almost identical inertia. The usual reaction is to treat the spread as noise from the random number generator and keep the best-scoring run. That reading is wrong in an interesting way. The difficulty is in the objective itself, and it has been quantified.

Lloyd's iteration can require 2^Ω(n) iterations on a data set of n points lying in the plane. Andrea Vattani proved that in 2011. The earlier bound, from Arthur and Vassilvitskii, was 2^Ω(√n), and it needed d = Ω(√n) dimensions to construct; Vattani brought the exponential blow-up down into two dimensions. Tim Roughgarden and Joshua R. Wang summarised the position in 2016: “The worst-case running time of the method is exponential in the number of points. This was first proved by Arthur and Vassilvitskii [4], and extended to the plane by Vattani [18].”

The worst case is a construction, not the typical run. But it settles what the disagreement between seeds means. The landscape the procedure descends genuinely contains competing solutions. The partition you got is the one your initialization happened to reach, and the differences between restarts are evidence about the problem you are looking at.

Initialization sensitivity is evidence about the problem, not only an inconvenience.

Visual

Four questions hidden inside “choose K”

Choosing the cluster count folds four different questions into one number. Only the first of them is about the optimizer at all.

Can the optimizer find a strong solution? In general, provably not. Finding the optimal k-means partition is NP-hard, and it stays NP-hard at both extremes of the problem. It is NP-hard for just two clusters in general dimension: Aloise and three colleagues published that short proof in 2009, written because an earlier proof, by Drineas and colleagues in 2004, was invalid. It is also NP-hard for points in the plane with general k, which Mahajan, Nimbhorkar and Varadarajan showed in 2012. Awasthi and three colleagues set both results out: “The work of Dasgupta [11] and Aloise et al. [1] showed that Euclidean k-means is NP-hard even for k = 2. Mahajan et al. [30] also show that the k-means problem is NP-hard for points in the plane.” Restarts buy better local solutions. They never convert the heuristic into a guarantee, and no count of them is a proof of optimality.

How much compression is acceptable? More clusters lower distortion and add complexity, and that tradeoff has no optimum inside the data. Does the partition persist? Seeds, resamples and preprocessing changes are the test. Can anyone act on the groups? Operational capacity and real domain distinctions constrain the useful range. That last constraint is about the organisation, not about the population.

FigureLayers · 4 layers
  1. 01

    Can the optimizer find a strong solution?

    Initialization and restarts determine which local minimum is reached.

  2. 02

    How much compression is acceptable?

    More clusters lower distortion but create more complexity.

  3. 03

    Does the partition persist?

    Seeds, samples, and preprocessing changes reveal stability.

  4. 04

    Can anyone act on the groups?

    Operational capacity and domain distinctions constrain useful K.

K is a modeling and product decision, not a number revealed by one curve.

Comparison

Evidence sources for candidate K values

Each method answers a narrower question than “How many real groups exist?”, and for three of them there is a measured track record to consult rather than an intuition.

The elbow curve plots inertia against K and looks for diminishing returns. It always trends downward. It may show no visible bend. It depends on feature geometry, and the scaling result above moves it. It is also conspicuously absent from the literature that benchmarked stopping rules. Glenn W. Milligan and Martha C. Cooper ran a Monte Carlo study in 1985, and its abstract opens: “A Monte Carlo evaluation of 30 procedures for determining the number of clusters was conducted on artificial data sets which contained either 2, 3, 4, or 5 distinct nonoverlapping clusters.” Arbelaitz and colleagues describe the same experiment from outside it: “They used 108 synthetic datasets with a varying number of non-overlapped clusters (2, 3, 4 or 5), dimensionality (4, 6 or 8) and cluster sizes.” Two rules came out on top, and neither reads a bend off a curve. StataCorp's manual reports the outcome and acts on it: “Milligan and Cooper (1985) evaluate 30 stopping rules, singling out the Caliński–Harabasz index and the Duda–Hart index as two of the best rules.” Stata ships exactly those two rules and no elbow rule.

Silhouette analysis measures cohesion relative to the nearest competing cluster. It can compare several K values, and it favors separated compact groups, which means it can penalize meaningful overlap. It also has the strongest measured record of the internal indices. Arbelaitz and four colleagues compared 30 internal cluster validity indices across 6,480 experimental configurations — 20 real UCI data sets plus synthetic ones, three clustering algorithms (k-means, Ward and average-linkage) and three partition-similarity measures — computing each index on 156,069 partitions. Their conclusion, published in 2013: “there is not a single CVI that showed clear advantage over the rest in every context, although Silhouette index obtained the best results in many of them”. The same study injected 10% random noise and watched the average success score fall to a third of its clean value. Best available is not the same as reliable.

The gap statistic replaces eyeballing with a comparison against a null. Robert Tibshirani and two colleagues described it in 2001, in an abstract that says what it does: “The technique uses the output of any clustering algorithm (e.g. K-means or hierarchical), comparing the change in within-cluster dispersion with that expected under an appropriate reference null distribution.” Better founded, and still not a verdict. In Schubert's 2023 evaluation it chose 30 clusters where the true k was 25, and 14 to 21 clusters on uniform noise whose true k was 1. Its answers also fluctuate with the random seed.

Stability analysis compares partitions across seeds, samples or perturbations. It reveals fragile boundaries. It needs label alignment or a partition metric, it can favor coarse solutions, and it does not prove usefulness. Domain and capacity constraints connect K to the actions available. They can cap complexity, they may encode existing organizational bias, and they should be tested rather than assumed.

FigureComparison · 4 columns

Elbow curve

Plots inertia against K and looks for diminishing returns.

  • Shows compression tradeoff
  • May have no visible elbow
  • Always trends downward
  • Depends on feature geometry

Silhouette analysis

Measures cohesion relative to the nearest competing cluster.

  • Can compare several K values
  • Favors separated compact groups
  • Needs point-level inspection
  • Can penalize meaningful overlap

Stability analysis

Compares partitions across seeds, samples, or perturbations.

  • Reveals fragile boundaries
  • Requires label alignment or partition metrics
  • Can favor coarse solutions
  • Does not prove usefulness

Domain and capacity constraints

Uses available actions, review teams, or natural operational levels.

  • Connects K to intended use
  • Can limit complexity
  • May encode existing organizational bias
  • Should be tested rather than assumed

Analogy

Placing emergency depots before knowing traffic patterns

K emergency depots go down first, every neighborhood is assigned to its nearest one, and each depot then moves toward the average demand location. Poor initial placement can trap the system in an inefficient arrangement.

Depot planners would also weigh roads, fixed sites, capacity, and asymmetric costs. K-Means++ improves starting spread only within the simplified squared-distance model. David Arthur and Sergei Vassilvitskii quantified that improvement in 2007. Their seeding rule picks each new center with probability proportional to its squared distance from the nearest center chosen so far. The resulting algorithm is “Θ(log k)-competitive with the optimal clustering”. The bound is on expected cost. It is a factor rather than a solution, and it says nothing about any single run — which is what one should expect of a problem that is NP-hard even for two clusters.

Better starting points reduce avoidable failures but do not repair a mismatched objective.

Steps

Select K with a reproducible decision table

Compare a bounded range of candidates, and preserve conflicting evidence. Bound K by domain limits, sample size and the smallest group anyone could act on. Run K-Means++ with enough independent initializations to expose local variation. Record inertia, silhouette distribution, cluster sizes and boundary margins. Repeat on resamples and on plausible preprocessing variants, then align the partitions. Check that each candidate supports distinct, feasible and ethical actions. Write down why the simpler and the more complex K values were rejected.

Two of those steps carry the anchored results. When collecting diagnostics, prefer a rule with a published track record. The Caliński–Harabasz variance-ratio index and the Duda–Hart Je(2)/Je(1) index have had one since the 1985 benchmark by Milligan and Cooper, and the gap statistic compares against a reference null distribution instead of against your eye. When testing perturbations, treat scaling as one of them: rescaling the data by α multiplies SSE by α² and moves the geometric optimum, so the scaling you fitted on belongs in the record. So does the seed. Schubert's own table marks the gap statistic's answers on several toy sets as results that fluctuate with random seeds, and an undocumented seed makes a K value unreproducible even when the pipeline is.

FigureProcess · 6 steps
  1. 1. Define candidate range

    Use domain limits, sample size, and minimum useful group size to bound K.

  2. 2. Run robust starts

    Use K-Means++ and enough independent initializations to expose local variation.

  3. 3. Collect diagnostics

    Record inertia, silhouette distribution, cluster sizes, and boundary margins.

  4. 4. Test perturbations

    Repeat on resamples and plausible preprocessing variants, then align partitions.

  5. 5. Review actionability

    Check whether each candidate supports distinct, feasible, and ethical actions.

  6. 6. Document rejection

    Explain why simpler and more complex K values were not selected.

Sometimes the right answer is a range, not a single K

A dataset may support stable broad regimes and several plausible finer subdivisions. Forcing one count can hide that hierarchy or uncertainty. The final choice should reflect the level at which decisions remain stable and useful. When no candidate survives perturbation and review, report the absence of reliable partition evidence.

Stability is a narrower instrument than it looks. Idealized K-Means stays stable on asymmetric data even when K is wrong, and Ulrike von Luxburg's survey of the method puts it flatly: “Instability of the wrong number of clusters only occurs in symmetric data sets.” A stable K can therefore be a wrong K. That is one more reason to report the range that survived rather than the single number that scored best.

K selection is complete only when rejected alternatives are understood.

Position

K is a decision somebody makes, and no curve makes it for them

Whoever reports K has made a choice. The elbow plot and the silhouette score are what make that choice resemble a measurement, and the number coming out of them gets reported as though it had been found in the data. But this lesson has already broken “choose K” into four questions. Two of the four are about how much complexity a team can accept and act on, not about the population at all.

The elbow's own originator said as much, seventy years ago. The method traces to Robert L. Thorndike's presidential address to the Psychometric Society in 1953, published in Psychometrika as Who Belongs in the Family? Thorndike's verdict on his own curves, quoted verbatim by Erich Schubert seventy years later, was this: “The curves do not provide much support for the intuitive specification of the number of clusters”. Schubert's eight automated elbow detectors returned 4 to 6 clusters on data containing none. The disclaimer and the measurement agree.

The silhouette narrows the question differently. It favors separated compact groups and can penalize meaningful overlap, so it reports which K looks most like tidy balls in the representation somebody happened to build. It was still the best of the thirty indices Arbelaitz and colleagues tested, until 10% noise cut the average score to a third. Stability, the usual last resort, is narrower than it looks too. Idealized K-Means stays stable on asymmetric data even when K is wrong. Von Luxburg's survey says it in one line: “Instability of the wrong number of clusters only occurs in symmetric data sets.” A stable K can be a wrong K.

None of that makes the diagnostics worthless. It makes them evidence rather than verdicts, and it leaves the choice where it started. Somebody picks K. The defensible version of that names the compression accepted, the scaling and seed it was computed under, the operational capacity assumed, and the alternatives rejected. When no candidate survives perturbation and review, the reportable result is the absence of reliable partition evidence.

A stable K can still be the wrong K, and no single curve will tell you which.

Key takeaways