Foundations to Frontier
Tests

HDBSCAN

HDBSCAN (Campello, Moulavi and Sander, 2013) removes DBSCAN's single density threshold. It replaces distances with mutual reachability distances, which push sparse points apart, and builds the single-linkage hierarchy of that metric: DBSCAN at every ε at once. It then condenses the hierarchy, ignoring splits that only shed fewer than min_cluster_size points, and selects the clusters that persist longest (highest stability, or excess of mass). Clusters at different densities can therefore coexist, and the main parameter is an intuitive minimum cluster size. This page covers core and mutual reachability distances, the MST construction, the condensed tree, stability and selection, the role of min_samples, and limits. In the exercises you implement HDBSCAN end to end; then you compare it with DBSCAN tuned by an oracle and test its sensitivity to min_cluster_size.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

DBSCAN at every density, then keep what lasts

DBSCAN needs one radius ε, so it can’t see a dense cluster and a sparse cluster at the same time. HDBSCAN effectively tries every ε:

  • at very small ε only the densest cores exist;
  • as ε grows, clusters appear, grow, split or merge;
  • in the end, for each region it keeps the version that lasted longest.

You choose only the smallest group size worth calling a cluster.

HDBSCAN: density clustering without choosing ε
××××××××××
clusterpointsstability
● 1102145
● 21091608
● 31091900
clusters 3 · noise 10 of 330
HDBSCAN effectively runs DBSCAN at every ε at once and keeps, for each region, the density level where its cluster is most stable (persists longest). So the two tight blobs and the sparse blob can all be found together, which no single ε managed. min cluster size is the smallest group worth calling a cluster. If no split ever yields two pieces at least that big, nothing is selected and every point is labelled noise. Try a size above 160 (each moon has 160 points) on the moons.
Why engineers care

Telemetry, trajectories and sensor point clouds rarely have one density: a busy airport and a quiet one, dense lidar returns up close and sparse ones far away. HDBSCAN handles that with almost no tuning, labels outliers as noise, and gives each point a membership strength. It has become the default density-based clusterer in practice (it is also in scikit-learn).

📝 Quick check (Level 0)
0/3 answered
  1. 1. HDBSCAN avoids choosing…
  2. 2. Its main parameter is…
  3. 3. HDBSCAN keeps the clusters that…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Core and mutual reachability distances by hand

Core distance. The distance to the k-th nearest point, counting the point itself as the first. For points 0, 1, 3, 7 with k = 2 this is each point’s distance to its nearest other point: 1, 1, 2, 4.

Mutual reachability distance (MRD). d_mreach(a, b) = max(core(a), core(b), d(a, b)).

  • MRD(1, 3) = max(1, 2, 2) = 2.
  • MRD(3, 7) = max(2, 4, 4) = 4.
  • MRD(0, 7) = max(1, 4, 7) = 7.

Points in sparse areas have large core distances, so they are pushed away from everything. Dense points keep their true distances.

λ = 1/distance. HDBSCAN measures “how long a cluster lasts” in λ. A merge at distance 0.5 happens at λ = 2.

Stability. For a cluster born at λ_birth, stability = Σ over its points of (λ at which the point leaves − λ_birth). Three points leaving at λ = 2, 3, 5 from a cluster born at λ = 1 give 1 + 2 + 4 = 7.

The steps in plain English:

  1. Compute core distances (k = min_samples) and mutual reachability distances.
  2. Build the minimum spanning tree of the MRD graph, and sort its edges into a single-linkage hierarchy.
  3. Condense the tree: walk down from the root. A split counts only if both sides have at least min_cluster_size points; otherwise the small side’s points just “fall out” of the cluster.
  4. Compute each condensed cluster’s stability. Select clusters bottom-up: keep a cluster if its stability beats the total of its best descendants. Points outside the selected clusters are noise.
📝 Quick check (Level 1)
0/3 answered
  1. 1. MRD(a, b) when core(a) = 3, core(b) = 1, d(a, b) = 2?
  2. 2. λ for a merge at distance 0.25?
  3. 3. A split where one side has fewer than min_cluster_size points…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Why mutual reachability, and how selection works

MRD smooths density. Taking the max with core distances means two points can be “close” only if both live in regions where k neighbours are close. Single linkage on MRD is therefore robust single linkage: thin chains of sparse points no longer connect clusters. Single linkage at MRD level ε gives exactly the DBSCAN* clusters at ε, with minPts = min_samples. So the hierarchy contains DBSCAN’s answer for every ε.

Condensed tree and excess of mass. Most splits in a single-linkage tree just shed a point or two. Condensing keeps only real splits, where both children have at least min_cluster_size points. A cluster’s stability, Σ(λ_leave − λ_birth), is the area it occupies in the condensed tree.

Selection is a small dynamic programme over the tree. A parent is kept if its stability is at least the sum of the best selection among its children. This maximises total stability under the rule that no point belongs to two selected clusters. The root is never selected by default.

Exercise 1 used two tight blobs and a sparse blob, where the best single-ε DBSCAN averaged ARI 0.745. HDBSCAN (min cluster size 15) found all 3 clusters with 9 noise points (ARI 0.970). The stabilities were about 2268 and 2056 for the tight blobs and 237 for the sparse one. Dense clusters live at high λ, but even a modest stability is enough when it beats its alternatives.

Parameters.

  • min_cluster_size is the smallest group you’d call a cluster.
  • min_samples (defaults to min_cluster_size) controls smoothing. Larger values make more points noise and merge thin structures.
  • If no split ever produces two children of at least min_cluster_size points, nothing is selected and everything is noise. Use allow_single_cluster if one cluster is a valid answer.
from sklearn.cluster import HDBSCAN          # or: import hdbscan
hd = HDBSCAN(min_cluster_size=15, min_samples=10).fit(X)
hd.labels_, hd.probabilities_                # −1 = noise; membership strengths in [0, 1]
🐍 Exercise 1: HDBSCAN from scratch
Implement mutual reachability distances, the MST-based single-linkage tree, the condensed tree with stabilities, and excess-of-mass selection; recover two tight blobs and a sparse blob that defeat any single ε.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Single linkage on MRD at level ε gives…
  2. 2. Stability is the cluster's…
  3. 3. By default the root cluster is…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Density level-set hierarchy. For a density estimate f, the clusters at level λ are the connected components of the set where f ≥ λ. Hartigan’s cluster tree collects them over all λ. HDBSCAN’s hierarchy is a consistent estimator of this tree, using the k-NN density implied by core distances. Stability-based selection then picks a flat clustering from the tree, with clusters taken at different levels.

Cost. Mutual reachability needs k-NN queries, about O(n log n) with trees in low dimension. The MST of the MRD graph takes O(n²) naively, or near O(n log n) with dual-tree Borůvka in low dimension (McInnes and Healy, 2017). Condensing and selection are linear in n.

Soft outputs.

  • The membership “probability” of a point is how long it stays in its cluster, relative to the cluster’s most persistent point.
  • The GLOSH outlier score, 1 − λ_point/λ_max of its cluster, measures how much of an outlier a point is.

Interview questions.

  • How does HDBSCAN improve on DBSCAN? It handles varying densities, has no ε, gives a hierarchy and soft memberships, and its parameters are more intuitive.
  • What still goes wrong? In high dimensions distances concentrate, so reduce dimension first (UMAP followed by HDBSCAN is a popular pipeline). Very large min_samples over-smooths, and clusters smaller than min_cluster_size can’t be found.
📝 Quick check (Level 3)
0/3 answered
  1. 1. HDBSCAN estimates…
  2. 2. GLOSH is…
  3. 3. A popular pipeline for high-dimensional data is…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Does HDBSCAN beat a perfectly tuned DBSCAN?

History.

  • J. Hartigan (1975) defined the density cluster tree.
  • R. Campello, D. Moulavi and J. Sander introduced HDBSCAN (2013, extended in 2015).
  • L. McInnes, J. Healy and S. Astels released the hdbscan Python library (2017) with fast MST construction.
  • scikit-learn added HDBSCAN in version 1.3 (2023).

Exercise 2. min_samples = min_cluster_size, 3 datasets each. Values are ARI on the real points, with points called noise counted as singletons. For the DBSCAN baseline, ε was tuned separately on each dataset against the true labels, an oracle no real user has.

data HDBSCAN, size 5 10 20 40 80 DBSCAN, oracle ε
moons + noise 1.000 0.998 0.987 0.810 0.000 1.000
two tight + one sparse blob 0.982 0.967 0.937 0.891 0.593 0.778
  • On mixed densities HDBSCAN beat even the oracle-tuned DBSCAN (0.98 against 0.78), and it stayed above 0.89 for minimum sizes 5 to 40. No single ε can do what its per-cluster density levels do.
  • On the moons both were perfect.
  • Too large a size broke it. At 80 (with min_samples also 80), the heavy smoothing meant the moons never split into two pieces of at least 80 points, the root is not selectable, and every point was labelled noise (ARI 0). Decoupling min_samples, or allowing a single cluster, avoids that trap.
🐍 Exercise 2 (research): HDBSCAN versus oracle DBSCAN
On moons with noise and on blobs of different density, run HDBSCAN for min cluster sizes 5–80 and compare with DBSCAN using the best ε per dataset.

HDBSCAN in AI, robotics and aerospace

  • Air-traffic analytics: clustering trajectories or positions across busy and quiet regions without per-region tuning.
  • Lidar segmentation where point density falls with range.
  • Embedding clustering: grouping reports, images or telemetry windows after UMAP, with noise for one-offs.

References

  1. R. J. G. B. Campello, D. Moulavi, J. Sander (2013). “Density-based clustering based on hierarchical density estimates.” Proc. PAKDD.
  2. R. J. G. B. Campello, D. Moulavi, A. Zimek, J. Sander (2015). “Hierarchical density estimates for data clustering, visualization, and outlier detection.” ACM TKDD 10(1).
  3. L. McInnes, J. Healy, S. Astels (2017). “hdbscan: hierarchical density based clustering.” Journal of Open Source Software 2(11).
  4. L. McInnes, J. Healy (2017). “Accelerated hierarchical density based clustering.” Proc. ICDM Workshops.
  5. J. A. Hartigan (1975). Clustering Algorithms. Wiley.