How would you use resampling to test whether a k=4 clustering reflects real structure?
answer
- no labels, so make your own comparison
- cluster many subsamples, not one
- compare runs to each other, not to the full fit
- score on the rows they share
- reproducible is not the same as correct
basics
~20 sRe-cluster many random subsamples of the data and measure how much the resulting partitions agree with each other, usually as the mean pairwise adjusted Rand index over the points any two subsamples share. Tight, high agreement suggests reproducible structure.
solid answer
~50 sDraw around 50 subsamples of about 80% of the rows, run the whole pipeline — scaling included, refitted inside each subsample — on each, then for every pair of subsamples restrict to the rows they share and compute the adjusted Rand index between their assignments. Report the mean and the spread, not the mean alone. Repeat for each candidate k: on a mobile-app user table, k=4 averaging 0.71 tightly against k=7 averaging 0.34 widely says the four-way split reproduces and the seven-way one is largely an artefact of which rows you drew. The adjusted Rand index is the right measure because it ignores cluster ids, which differ arbitrarily between runs, and its chance baseline is comparable across k. State the caveat: stability is necessary but not sufficient, and a trivial two-way split is often the most stable thing you can produce.
go deeper
Be ready to describe the basic loop: cluster many random subsets, then check whether the same points keep landing together. Know that cluster numbers are arbitrary and cannot be compared directly across runs.
Explain the mechanics — subsample, refit the whole pipeline, score pairs of runs on their shared rows with a chance-corrected agreement measure — and why fitting preprocessing on the full data first invalidates the study.
Demonstrate that you have run one: report the spread as well as the mean, separate initialisation variance from sampling variance, and state plainly that stability is necessary but not sufficient.
Own what the evidence is allowed to decide. Set the standard that a partition ships only with a reproducibility check plus a downstream measure of usefulness, and resist stability curves being used as the sole argument for a number of clusters.
## The idea With no label set, external agreement is unavailable, so you manufacture a comparison out of the data itself. If a partition reflects structure in the population, a clustering fitted on one random 80% of the rows should assign the shared points roughly the same way as a clustering fitted on a different 80%. If the partition is an artefact of noise or of the algorithm's starting conditions, the two runs will disagree. ## The procedure 1. Fix a candidate k. 2. Draw `B` resamples — commonly 50 subsamples at 80% without replacement, or bootstrap draws with replacement; subsampling is easier to reason about because duplicated points distort distance-based methods. 3. On each resample, run the **entire** pipeline: imputation, scaling, any dimensionality reduction, and the clustering. Fitting the scaler once on the full data and reusing it leaks population information into every resample and makes the result look more stable than it is. 4. For each of the `C(B,2)` pairs of resamples, restrict to the intersection of their row sets — each clustering only labels its own rows, and an agreement measure needs both labelings on the same points — and compute the adjusted Rand index there. 5. Report the mean and the distribution: the spread, the minimum, a histogram. A mean of 0.7 built from values ranging 0.2 to 0.95 is a different finding from a mean of 0.7 with everything between 0.65 and 0.75. 6. Repeat for each candidate k and compare like with like. A variant that gives more diagnostic detail is the co-membership or consensus matrix: for every pair of points, record the fraction of resamples in which they landed in the same cluster, counted only over resamples containing both. A clean block structure in that matrix means agreement; smeared blocks localise *which* clusters are unstable, which the single scalar cannot. ## Why the adjusted Rand index specifically Two runs produce cluster ids that mean nothing to each other — the group labelled 1 in one run may be labelled 3 in the other. Any measure comparing ids directly would need a matching step. Pair-counting agreement sidesteps this by only asking whether two points ended up together, and the chance correction means the number does not drift upward simply because k is larger, which matters because the whole point is to compare across k. ## Pitfalls that make a stability study lie - **Comparing every resample to the full-data clustering instead of to each other.** The full-data model saw all the rows in each resample, so the comparison is optimistic. Pairwise comparisons among resamples are the honest version. - **Leaking preprocessing**, as above. - **Confounding two sources of variance.** Instability can come from the sampling or from the algorithm's own randomness, such as centroid initialisation. Separate them: run repeated restarts with different seeds on the *full* data first. If those already disagree, the instability is in the algorithm, and the fix is more restarts or better initialisation, not a different k. - **Reading the mean alone.** One badly unstable cluster can hide inside a respectable average. - **Treating a number as an absolute grade.** There is no universal threshold; the comparison is relative, between candidate k values and against a shuffled or null-structure baseline if you want one. ## The honest limitation Stability is necessary, not sufficient. A clustering that fails to reproduce is not trustworthy, but reproducing does not make it correct or useful. Trivial partitions are frequently the most stable: splitting along one dominant, high-variance direction reproduces beautifully every time while carrying little information. Small k is structurally favoured because there are fewer boundaries to get wrong, so a stability curve that peaks at k=2 should be read sceptically rather than obeyed. So stability is one leg of the argument. In practice you present it alongside whatever else is available — external agreement if any label set exists, geometric evidence, and above all whether the partition is any use for the decision it was built to support. State it that way in an interview: resampling stability tells you a partition is reproducible, and reproducibility is a prerequisite for everything else you might want to claim about it.
- Why compute the agreement only on the intersection of two subsamples?Because each clustering assigns labels only to the rows it was fitted on, and a pair-counting agreement measure needs both partitions defined over the same points. Restricting to the shared rows is the clean fix. The alternative is to extend each model to the missing rows — assigning them to the nearest centroid, say — but that imports the model's own extrapolation into the measurement, so the intersection is the more honest comparison.
- If stability peaks at k=2, does that settle the number of clusters?No. Small k is structurally advantaged: fewer boundaries exist to be drawn differently, so coarse partitions reproduce more easily even when they carry little information. Stability is a necessary condition, not a selection criterion on its own. Treat a k=2 peak as a warning that the stability curve is measuring difficulty rather than structure, and weigh it against other evidence and the decision the partition has to support.
- How do you separate instability caused by resampling from instability caused by the algorithm itself?Hold the data fixed and vary only the seed: run many restarts of the clustering on the full dataset and compute the same pairwise agreement. If those runs already disagree, the instability lives in the initialisation, and the remedy is more restarts or a better seeding scheme rather than a different k. Only the excess disagreement seen when you also resample rows is attributable to sampling variability.
- What does a consensus matrix add over the mean pairwise agreement score?Localisation. The mean is one number for the whole partition, so a single unstable cluster can hide inside a healthy average. Recording, for each pair of points, the fraction of resamples containing both in which they were co-clustered gives a matrix whose block structure shows exactly which groups reproduce and which dissolve, which is what you need to decide whether to merge, drop or keep a cluster.
Asking whether a coastline has four bays: photograph it fifty times from slightly different angles and see whether four bays show up every time, or whether the count changes with the vantage point.
saying these in an interview costs you the question
- Concludes that a stable clustering must be the correct one
- Compares each resample against the full-data clustering only
- Fits scaling once on all rows before resampling
- Matches cluster ids across runs instead of comparing point pairs
- Reports only the mean agreement and never its spread