The gap statistic compares (the log within-cluster dispersion) with its expectation under a reference null with no cluster structure. For suppose , the reference expectations are , and all . Compute the gaps and choose by the standard "one standard error" rule. Why not pick the with the largest gap?
Unsupervised learning, Choosing k
Level L3 Intermediate. Length Medium. Nature Th+Mat Both.
What's being asked
Whether you can apply the gap statistic rule and understand why it prefers the smallest adequate .
Key idea
, where is the average over reference datasets (uniform over the data's range or box of its principal components). Choose the smallest such that , where is the simulation standard error (scaled by for reference sets).
Steps
- Gaps: , , , , .
- Test : is ? No.
- Test : is ? Yes. So the rule chooses .
- The largest gap is at (0.58), but it is larger than the gap by only , which is less than the standard error . The difference is within simulation noise, so the simpler model wins.
- Explain the reason for the reference: always decreases with , so by itself it cannot select . The gap measures how much faster it falls than it would for structureless data.
- Note that is allowed, so the method can say there are no clusters, which the elbow method cannot.
Common mistakes
- Selecting the maximum gap directly, which tends to favour larger by noise.
- Using instead of . The log makes the comparison with the reference scale-free.
- Forgetting that the reference distribution matters. A uniform box can mislead for correlated data, so a PCA-aligned box is often used.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Unsupervised learning: CURE represents each cluster by several well-scattered representative points that are shrunk towards the cluster centroid by a factor . In 2-D, a cluster with centroid has a representative at . With , where does it go? Why does the shrinking help, and what happens at and ?
Next in Unsupervised learning: Three points have pairwise distances , and . Use classical multidimensional scaling (MDS) with double centring to find the matrix and the 1-D embedding. Why is one dimension enough?