When groups are not round blobs: DBSCAN (density-based spatial clustering of applications with noise), its hierarchical version HDBSCAN, and how to choose an algorithm
Each group is a convex cell with straight boundaries halfway between centers, and every point pays the same squared distance:
ARI (Adjusted Rand Index): agreement with the true groups, 1 = identical, about 0 = chance. Predict. Which shapes will k-means recover? Will the silhouette warn you about the others?
| data | \(k\) | silhouette | ARI |
|---|---|---|---|
| blobs | 3 | 0.823 | 1.000 |
| moons | 2 | 0.489 | 0.253 |
| circles | 2 | 0.356 | −0.002 |
| anisotropic | 3 | 0.501 | 0.555 |
| densities | 3 | 0.605 | 0.436 |
Try. Cycle through the shapes and vary \(k\). Is there a \(k\) that fixes a ring?
k-means returns one flat partition for one chosen \(k\). Agglomerative clustering builds the whole tree of merges, the dendrogram, and lets you choose the number of groups afterwards by cutting it.
A group is a dense region, separated by sparse ones. Two parameters: a radius eps and a count min_samples.
at least min_samples points within eps, itself included
not core, but within eps of a core point
neither: label −1, not forced into a group
eps = 1.5, min_samples = 4A, B, C, D: the left square (D also sees E); G, H, I, J: the right one. E = (3, 3) sees D and F; F = (4, 4) sees only E.
eps of E, and E belongs to a cluster. Is F in the cluster?No: E has only 3 points within 1.5, so it is a border point, and clusters grow only through core points. F is noise.
eps: one value, one densityThe k-distance plot: each point's distance to its \(k\)-th neighbor, sorted; read eps at the knee. "Densities": the tight groups need about 0.07, the loose one about 0.3.
eps | 0.15 | 0.3 | 0.6 | 0.8 |
|---|---|---|---|---|
| clusters | 8 | 6 | 2 | 1 |
| noise | 172 | 63 | 5 | 4 |
| ARI | 0.825 | 0.397 | 0.619 | −0.003 |
eps means one density.eps at onceRuns DBSCAN for every eps, builds a hierarchy of clusters and keeps those that persist the longest, each at its own density. One parameter: min_cluster_size.
| HDBSCAN, no \(k\) | blobs | moons | circles | anisotropic | densities |
|---|---|---|---|---|---|
| clusters · noise | 3 · 0 | 2 · 0 | 2 · 0 | 3 · 49 | 3 · 45 |
| ARI | 1.000 | 1.000 | 1.000 | 0.852 | 0.856 |
The noise points are tails and fringes; the assigned ones are all right. This is why BERTopic uses HDBSCAN.
| k-means | hierarchical (Ward) | DBSCAN | HDBSCAN | |
|---|---|---|---|---|
| a group is | nearest a center | a branch of merges | a dense region | dense, at its own density |
| you choose | \(k\) | the cut (\(k\)) | eps, min_samples | min_cluster_size |
| shapes | convex, round | depends on the linkage | any | any, mixed densities |
| noise | forced in | forced in | −1 | −1 |
| new points | predict | no | no | no |
eps means one density; HDBSCAN keeps each cluster at its own density, with one parameter, min_cluster_size.df, X, Z, scalers, labels and cultivar from steps 1 to 6.Pace: step 7 and the first simulation in 10 min; step 8 in 5 min; step 9 and the second in 10 min.