- Introduced by
- Campello, R.J.G.B.; Moulavi, D.; Zimek, A.; Sander, J.
- Year
- 2015
- Type
- Hierarchical density-based clustering with robust single-linkage
- Family
- Machine learning
What does it do?
HDBSCAN* is a density-based clustering method, introduced in full by Campello et al. (2015), that builds a hierarchy of density-based clusters across all density thresholds and then extracts a flat partition from it.
It is also referred to as Robust HDBSCAN. The framework labels low-density points as noise, can produce normalised outlier scores, and does not require the number of clusters to be fixed in advance. Its central quantities are the core distance and the mutual reachability distance.
The intuition behind the method
Imagine the data as a landscape in which dense groups of points form hills. Lower a water level gradually: as it drops, separate hills merge into one. Robust HDBSCAN records this merging for every density level at once, producing a tree of nested clusters. It then keeps the clusters that stay distinct over a wide range of density levels, and points that belong to no retained cluster are labelled as noise.
History
The framework is presented in Campello, Moulavi, Zimek and Sander (2015), published in ACM Transactions on Knowledge Discovery from Data, which formalises hierarchical density estimates and stability-based cluster extraction. McInnes, Healy and Astels (2017) describe an open-source implementation, and this made the method widely available. Earlier conference versions of the HDBSCAN algorithm exist, but the sources cited on this page do not cover them.
When to use it
Choose Robust HDBSCAN when clusters may differ in shape, size and density, when the data contain noise or outliers, and when the number of clusters is unknown. It applies to metric spaces, usually Euclidean, and it is most sensible for continuous or embedded representations, where nearest-neighbour distances are meaningful. Do not use it for purely categorical data unless a suitable distance is defined, and do not use it on very high-dimensional raw features without first reducing dimensionality. If you need a fixed number of clusters, centroid-based summaries, or identical tie-broken results on data with many equal distances, k-means or a Gaussian Mixture Model is a more suitable choice.
Limitations and considerations
- The results depend on the min_cluster_size parameter, which must be chosen from domain knowledge or by careful comparison of results.
- Nearest-neighbour core distances become less informative in high-dimensional raw feature spaces, so dimensionality reduction (for example UMAP) is often applied first.
- Excess-of-mass extraction is not always intuitive and may split or merge clusters unexpectedly where densities change gradually.
- Exact ties among mutual reachability distances can make the minimum spanning tree non-unique, so tie-breaking may change the clustering. This is uncommon with continuous data but possible in data with repeated values.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Does not require the number of clusters to be specified, and the hierarchy covers all density thresholds, so clusters of different densities can be recovered from one run.
- Labels points that match no stable cluster as noise instead of forcing every point into a cluster.
- The hierarchy can be post-processed into a normalised outlier score for each object, as described in Campello et al. (2015).
- Stability-based extraction keeps clusters that persist across density levels, which allows dense and sparse clusters to appear together in one partition.
- The 2015 framework also accepts partially labelled objects or instance-level constraints for semi-supervised clustering.
Applications
- Clustering text embeddings and document collections where topics vary in density and size.
- Exploratory clustering of high-dimensional feature spaces after UMAP or PCA reduction.
- Density-based grouping of continuous feature data in which the number of groups is unknown.
How it works
How it works
For each point, compute its core distance: the distance to its k-th nearest neighbour. Points in dense regions have small core distances, while points in sparse regions have large ones. The parameter k (called min_samples in common implementations) fixes which neighbour defines this distance, so it sets how local the density estimate is. A larger k smooths the estimate and tends to label more points as noise. k is chosen separately from min_cluster_size, and its default in a given implementation should be checked in that implementation's documentation.
Formula
d_{\text{core}}(x, k) = d(x, N_k(x))For each pair of points, the mutual reachability distance is the largest of the two core distances and the ordinary distance between them. Any pair involving a sparse point is pushed further apart, so chains of connections through low-density areas are weakened. Because k enters through the core distances, changing k changes every distance used to build the hierarchy.
Formula
d_{\text{mreach}}(x, y) = \max(d_{\text{core}}(x,k),\, d_{\text{core}}(y,k),\, d(x,y))Build a minimum spanning tree over the points, using mutual reachability distances as edge weights. Each edge weight marks the density level at which two parts of the data become connected. If several edges share the same weight, the tree is not unique, and the tie-breaking rule can affect the result.
Removing MST edges from the largest weight downward yields a single-linkage hierarchy, in which each edge weight is the density level at which a component splits. This hierarchy contains clusters for all density thresholds, so no single cut has to be chosen in advance.
Walk the hierarchy from the top down. A split is treated as a genuine division only if both branches contain at least the minimum cluster size; otherwise the smaller branch is regarded as points falling out of the parent cluster. This converts the dendrogram into a condensed tree of persistent clusters, so the min_cluster_size parameter sets how small a cluster may be and still be kept.
Each candidate cluster in the condensed tree receives a stability score (excess of mass) that reflects how long its points remain grouped as the density threshold changes. Selecting a set of non-overlapping clusters that maximises total stability gives the flat partition. Points outside every selected cluster are labelled as noise. Campello et al. (2015) show that this stability maximisation can be solved globally and optimally in the unsupervised case.
Common pitfalls
- Treating every labelled noise point as a true outlier without inspection; some may be valid members near a cluster boundary.
- Applying the algorithm directly to raw high-dimensional text or image features without first reducing dimensionality, which weakens the nearest-neighbour core distances on which the hierarchy is built.
- Choosing a min_cluster_size that is too small, so that noise fluctuations are kept as genuine micro-clusters.
- Forgetting to scale or normalise continuous features with very different ranges before computing distances, since the distances, and therefore the hierarchy, depend on the feature scales.
- Comparing results across datasets with different densities without re-tuning min_cluster_size.
Frequently asked questions
What is the most important hyperparameter to tune?
The minimum cluster size (min_cluster_size) controls the smallest meaningful cluster the algorithm will retain. Setting it too low causes noise points to form micro-clusters, while setting it too high merges genuinely distinct groups. The neighbour count k (min_samples) also matters, because it sets the core distances on which the whole hierarchy depends. A comparison of results across settings, guided by domain knowledge or a relative validity index such as DBCV, is a practical approach.
What does the Campello et al. (2015) framework contribute?
Campello et al. (2015) give the full HDBSCAN* framework. It builds a hierarchy of density-based clusters for all density thresholds, extracts a flat partition by stability maximisation (solved globally and optimally in the unsupervised case), derives normalised outlier scores, and can incorporate partially labelled objects or instance-level constraints. McInnes et al. (2017) describe the open-source implementation of the method.
How should I read the outlier score?
Campello et al. (2015) show how the hierarchy can be post-processed into a normalised outlierness score for each object, which combines global and local perspectives. The score is continuous and relative within a run. Higher values indicate more outlying objects, meaning objects that leave the cluster structure at lower density levels. This is a different output from the binary noise label, which reports only whether a point belongs to a selected cluster. The user must choose any threshold for treating an object as an outlier.
Can I use it on categorical or mixed data?
Robust HDBSCAN relies on distances between points, so it requires a metric suitable for the data. For purely categorical data you would need a distance such as Gower or Hamming distance. Mixed-type data requires careful preprocessing, and methods designed for mixed data, such as k-prototypes, may be more appropriate.
Does it scale to large datasets?
Cost is dominated by the nearest-neighbour search used to compute core distances, and exact search becomes expensive as the number of points grows. Approximate nearest-neighbour indexes are commonly used to reduce this cost. Campello et al. (2015) include an asymptotic complexity analysis, and the implementation described by McInnes et al. (2017) is the reference to check for practical performance.
How should I evaluate the clustering quality?
When ground-truth labels are unavailable, use the Density-Based Clustering Validation (DBCV) index, which is designed for density-based methods and accounts for noise and cluster separation. Silhouette scores assume roughly convex clusters, so treat them as supplementary.
Related methods
Sources
Campello, R.J.G.B., Moulavi, D., Zimek, A. & Sander, J. (2015). Hierarchical Density Estimates for Data Clustering, Visualization, and Outlier Detection. ACM Transactions on Knowledge Discovery from Data, 10(1), 5.
Open DOI referenceMcInnes, L., Healy, J. & Astels, S. (2017). hdbscan: Hierarchical density based clustering. Journal of Open Source Software, 2(11), 205.
Open DOI reference