HDBSCAN, short for hierarchical density-based spatial clustering of applications with noise, is an unsupervised clustering algorithm that builds a hierarchy of density-based clusters and then extracts the most stable ones, labeling points that belong to no dense region as noise. In machine learning it is widely used when the number of clusters is unknown and when clusters have different densities and irregular shapes.
HDBSCAN generalizes DBSCAN by effectively running it across all density thresholds at once. Instead of asking the user for a single neighborhood radius, it asks mainly for a minimum cluster size, which is far easier to reason about in real data.
How HDBSCAN builds and condenses a cluster hierarchy
The algorithm first estimates local density through the core distance: for each point, the distance to its k-th nearest neighbor, where k is set by the min_samples parameter. It then defines the mutual reachability distance between two points as the maximum of their two core distances and their actual distance. This transformation pushes sparse points away from everything else while leaving dense regions intact.
On the mutual reachability graph, HDBSCAN computes a minimum spanning tree and turns it into a single-linkage hierarchy. Cutting this tree at every possible distance would yield many candidate clusterings, so the algorithm condenses the tree: any split that produces a branch smaller than min_cluster_size is treated as points falling out of the parent cluster rather than as a new cluster.
Finally, each remaining cluster receives a stability score that sums how long its points persist as density increases. The excess of mass method selects the set of non-overlapping clusters with the greatest total stability, and every point not inside a selected cluster is labeled noise.
| Stage | Purpose | Output |
|---|---|---|
| Core distances | Estimate local density per point | One distance per point |
| Mutual reachability | Separate sparse from dense points | Transformed distance graph |
| Minimum spanning tree | Connect all points with minimal total weight | Tree of n – 1 edges |
| Condensed tree | Drop splits below minimum cluster size | Simplified cluster hierarchy |
| Stability selection | Pick the most persistent clusters | Flat labels plus noise |
Key parameters and their effects
HDBSCAN has few parameters, but each one changes results noticeably. Min_cluster_size is the most important and should reflect the smallest grouping that is meaningful in the domain.
| Parameter | Role | Effect of increasing it |
|---|---|---|
| min_cluster_size | Smallest group accepted as a cluster | Fewer, larger clusters |
| min_samples | Neighbor count for core distance | More conservative, more noise points |
| cluster_selection_epsilon | Merge clusters closer than this distance | Fewer micro-clusters in dense areas |
| cluster_selection_method | Excess of mass or leaf selection | Leaf gives many small homogeneous clusters |
| metric | Distance function, for example Euclidean or cosine | Changes the notion of neighborhood |
When min_samples is not set, most implementations make it equal to min_cluster_size. Lowering min_samples independently is a common way to reduce the share of noise without letting tiny clusters appear.
HDBSCAN compared with other clustering methods
HDBSCAN occupies a specific niche among clustering algorithms: it combines the noise handling of DBSCAN with the multi-scale view of hierarchical clustering. The table summarizes how it differs from common alternatives.
| Algorithm | Needs cluster count | Handles noise | Varying density |
|---|---|---|---|
| k-means clustering | Yes | No | No, assumes similar spherical clusters |
| Gaussian mixture model | Yes | No | Partly, through component variances |
| DBSCAN | No | Yes | No, one global radius |
| OPTICS | No | Yes | Yes, but extraction needs extra tuning |
| Hierarchical clustering | Cut level required | No | Depends on linkage |
| HDBSCAN | No | Yes | Yes, by stability selection |
The main practical advantage over DBSCAN is that no single epsilon must fit the whole dataset. Where DBSCAN either merges sparse clusters or fragments dense ones, HDBSCAN can keep a tight cluster and a diffuse cluster in the same result.
Soft clustering, outlier scores and practical use
Beyond hard labels, HDBSCAN offers membership probabilities that express how strongly each point belongs to its cluster and GLOSH outlier scores that rank points by how anomalous they are relative to their local density. These outputs make it useful for anomaly detection as well as segmentation.
A frequent workflow pairs HDBSCAN with dimensionality reduction. Text or image embeddings with hundreds of dimensions are first projected with UMAP to roughly 5 to 50 dimensions, where density estimates are more reliable, and HDBSCAN then groups the projected points. Topic modeling pipelines built on sentence embeddings commonly use exactly this UMAP plus HDBSCAN combination.
Limitations and common mistakes
HDBSCAN is robust, yet its results still depend on data preparation and interpretation. The following problems appear most often in practice.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Most points labeled noise | min_samples too high or data too sparse | Lower min_samples, reduce dimensions |
| One giant cluster | Excess of mass favors a large root branch | Try leaf selection or smaller min_cluster_size |
| Many tiny clusters | min_cluster_size too small | Raise it or set cluster_selection_epsilon |
| Slow on large data | Very high dimensionality hampers tree indexes | Reduce dimensions, use approximate neighbors |
| Unstable results across runs | Unscaled features or random projection seeds | Scale features, fix seeds upstream |
The curse of dimensionality is the most serious limitation: in high-dimensional spaces distances concentrate and density loses meaning. Users should also remember that noise is a valid output, not a failure, and should not force every point into a cluster without a clear reason.
Put simply
Picture a map of a country at night. Bright patches are cities. Some cities are huge and packed. Others are small towns. Scattered lights between them are lone farmhouses.
HDBSCAN looks at such a map and finds the cities on its own, big or small. You do not tell it how many cities exist. It also leaves the lone farmhouses unassigned instead of forcing them into a city. That makes it honest about points that do not fit anywhere.
In practice
A customer support team wants to discover recurring problems in about 40,000 support tickets without predefined categories. Analysts embed each ticket with a sentence embedding model, reduce the vectors to ten dimensions with UMAP, and run HDBSCAN with a minimum cluster size of 50 tickets.
The algorithm returns 37 clusters and labels roughly a quarter of the tickets as noise, which turn out to be one-off requests. Reviewing the largest clusters reveals a billing export bug and a confusing password reset flow that together account for many tickets. After both issues are fixed, the team reruns the pipeline monthly and uses the GLOSH outlier scores to flag unusual new tickets for manual review.