How does the gap statistic determine the optimal number of clusters?
Last updated
It compares log within-cluster dispersion W(k) on your data against its average on B structureless reference datasets (e.g. uniform over the bounding box): Gap(k) = mean_ref[log W(k)] − log W(k).
Choose the smallest k with Gap(k) ≥ Gap(k+1) − s(k+1), where s is the simulation standard error. This one-standard-error rule favors parsimony.
It can detect k = 1 (no structure), unlike silhouette. However, it is expensive, sensitive to the reference distribution, and assumes compact spherical clusters.