Skip to content
ML to LLMs
Cheat sheets

Clustering algorithms

K-means, DBSCAN, hierarchical, and Gaussian mixtures compared, with how to choose and validate.

MethodFindsNeeds K?Handles noise?CostFails on
K-meansround, similar-size clustersyesnoO(nKp)O(nKp) per iterationcurved shapes, unequal sizes, outliers
DBSCANdense regions of any shapeno (ε, min_samples)yes (label −1)~O(nlog⁡n)O(n\log n) to O(n2)O(n^2)varying densities, high dimensions
HDBSCANdensity clusters across scalesnoyessimilar to DBSCANvery high dimensions
Hierarchical (Ward)nested, compact clusterscut the treenoO(n2)O(n^2) memorylarge nn
Gaussian mixtureelliptical clusters, soft membershipyes (BIC helps)via low likelihoodO(nKp2)O(nKp^2) per iterationnon-Gaussian shapes

Always: scale features; try several K or parameter settings; check stability across seeds and subsamples.

Choosing K: elbow in inertia, silhouette score (−1 to 1), BIC for mixtures, and above all whether the clusters are useful.

Anomaly detection: DBSCAN noise, low mixture likelihood, distance to the nearest centroid, or Isolation Forest; thresholds need labeled incidents.

Key distinction

A discovered cluster is a hypothesis, not a verified real-world category.

Lessons: K-means · DBSCAN, hierarchical, and mixtures · Lab: K-means