CLASSICAL ML ยท INTERVIEW QUESTION
How do you determine the optimal number of clusters?
๐ก intermediate ยท Unsupervised Learning
Hint: Think about the elbow method, silhouette scores, and information criteria.
Answer
Methods:
-
Elbow method: plot within-cluster sum of squares (WCSS) vs K, look for the 'elbow' where improvement slows. Subjective but popular.
-
Silhouette analysis: measures how similar a point is to its own cluster vs other clusters. Score range [-1,1], higher is better. Average silhouette guides K selection.
-
Gap statistic: compares WCSS to null reference distribution.
-
Information criteria: BIC/AIC for Gaussian Mixture Models โ principled model selection.
-
Stability: run clustering multiple times, pick K with most consistent results.
-
Domain knowledge: often the most important factor.
Practical tips: try multiple K values, visualize with t-SNE/UMAP, validate clusters make business sense. DBSCAN and hierarchical clustering don't require K upfront.
Related questions
- Compare K-Means, DBSCAN, and hierarchical clustering. When would you use each?
- What is cluster analysis and what are its main applications?
- Explain Gaussian Mixture Models (GMM). How do they differ from K-Means?
- What is overfitting? How do you detect and prevent it?
- Explain the difference between bagging and boosting. When would you use each?