HDBSCAN

Also known as: Hierarchical density-based spatial clustering of applications with noise

On this page 7

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.

StagePurposeOutput
Core distancesEstimate local density per pointOne distance per point
Mutual reachabilitySeparate sparse from dense pointsTransformed distance graph
Minimum spanning treeConnect all points with minimal total weightTree of n – 1 edges
Condensed treeDrop splits below minimum cluster sizeSimplified cluster hierarchy
Stability selectionPick the most persistent clustersFlat labels plus noise
Stages of the HDBSCAN procedure

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.

ParameterRoleEffect of increasing it
min_cluster_sizeSmallest group accepted as a clusterFewer, larger clusters
min_samplesNeighbor count for core distanceMore conservative, more noise points
cluster_selection_epsilonMerge clusters closer than this distanceFewer micro-clusters in dense areas
cluster_selection_methodExcess of mass or leaf selectionLeaf gives many small homogeneous clusters
metricDistance function, for example Euclidean or cosineChanges the notion of neighborhood
Main HDBSCAN parameters

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.

AlgorithmNeeds cluster countHandles noiseVarying density
k-means clusteringYesNoNo, assumes similar spherical clusters
Gaussian mixture modelYesNoPartly, through component variances
DBSCANNoYesNo, one global radius
OPTICSNoYesYes, but extraction needs extra tuning
Hierarchical clusteringCut level requiredNoDepends on linkage
HDBSCANNoYesYes, by stability selection
Comparison with related clustering algorithms

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.

SymptomLikely causeRemedy
Most points labeled noisemin_samples too high or data too sparseLower min_samples, reduce dimensions
One giant clusterExcess of mass favors a large root branchTry leaf selection or smaller min_cluster_size
Many tiny clustersmin_cluster_size too smallRaise it or set cluster_selection_epsilon
Slow on large dataVery high dimensionality hampers tree indexesReduce dimensions, use approximate neighbors
Unstable results across runsUnscaled features or random projection seedsScale features, fix seeds upstream
Typical problems, causes and fixes

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.