What clustering is for
Clustering groups examples that look similar under some distance. Used well, it generates customer segments, anomaly candidates, or compact features for downstream models. Used badly, it produces beautiful charts that match nothing the business cares about.
Three algorithms with three intuitions
- K-Means — assumes K convex blobs of similar size; fast, scales to millions of rows.
- DBSCAN / HDBSCAN — density-based, finds arbitrary shapes, handles noise, leaves "unclustered" rows alone.
- Agglomerative — bottom-up hierarchy; great for small datasets where interpretability matters.
Picking K (or letting K pick itself)
For K-Means, plot inertia vs K (elbow) and silhouette score; pick the K where the elbow bends. For HDBSCAN, set min_cluster_size based on what would matter to the business ("a real segment is at least 200 customers"). Always validate clusters by inspecting examples, not by trusting the score alone.