How does the gap statistic determine the optimal number of clusters?

Quick Overview

Asks how the gap statistic chooses the number of clusters, from the quantity it measures to the rule that selects k. Tests understanding of within-cluster dispersion, structureless reference data, simulation error and the limits of compactness-based cluster selection.

How does the gap statistic determine the optimal number of clusters?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How does the gap statistic determine the optimal number of clusters? Walk through what it computes and the rule it uses to pick k. ```hint Ask what you compare against Within-cluster dispersion always falls as k grows. Think about how it would fall on data that has no clusters at all. ``` ```hint Account for noise in the comparison The reference curve is estimated by simulation. Consider how its uncertainty should change which k you pick. ``` ### What a Strong Answer Covers - The quantity measured for each k and why its raw curve cannot pick k alone - How the structureless reference datasets are generated and clustered - The gap formula on the log scale - The simulation standard error and the selection rule built on it - Strengths and limits, including detecting a single cluster, computational cost and sensitivity to the reference ### Follow-up Questions - Why does the gap compare log dispersions instead of the dispersions themselves? - When would a uniform reference over the bounding box mislead you, and how does a box aligned with the principal components help? - How would you apply the gap statistic to a method other than k-means, such as hierarchical clustering? - How do the gap statistic, the silhouette score and the elbow method behave on elongated or nested clusters?

Overview: Asks how the gap statistic chooses the number of clusters, from the quantity it measures to the rule that selects k. Tests understanding of within-cluster dispersion, structureless reference data, simulation error and the limits of compactness-based cluster selection.

PracHub logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How does the gap statistic determine the optimal number of clusters? Walk through what it computes and the rule it uses to pick k.

What a Strong Answer Covers Guidance

  • The quantity measured for each k and why its raw curve cannot pick k alone
  • How the structureless reference datasets are generated and clustered
  • The gap formula on the log scale
  • The simulation standard error and the selection rule built on it
  • Strengths and limits, including detecting a single cluster, computational cost and sensitivity to the reference

Follow-up Questions Guidance

  • Why does the gap compare log dispersions instead of the dispersions themselves?
  • When would a uniform reference over the bounding box mislead you, and how does a box aligned with the principal components help?
  • How would you apply the gap statistic to a method other than k-means, such as hierarchical clustering?
  • How do the gap statistic, the silhouette score and the elbow method behave on elongated or nested clusters?