What Is HDBSCAN? Hierarchical Density Clustering Explained
HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is a density-based clustering algorithm that groups data points into clusters of varying density while labeling sparse points as noise. It extends DBSCAN into a hierarchy, so instead of requiring one fixed distance threshold, it explores clusters across many density levels and keeps the ones that persist. Introduced by Campello, Moulavi, and Sander in 2013, its main tuning parameter is the minimum cluster size rather than a hard-to-pick distance cutoff.
The problem HDBSCAN solves
DBSCAN is simple and useful, but it depends on a parameter called epsilon ((\epsilon)), a distance radius that decides whether points count as neighbors. Set it well and DBSCAN works; set it poorly and the result falls apart. A single epsilon also struggles when the data contains clusters of different densities: a radius that separates tight clusters can merge loose ones, and a radius that fits the loose clusters splits the tight ones.
HDBSCAN removes the need to choose that single epsilon. It builds a full hierarchy of clusters at every density level, then extracts the clusters that stay stable rather than asking you to guess one threshold. The family of methods is introduced in the clustering overview.
Two distance ideas
HDBSCAN relies on two definitions before it clusters anything.
Core distance. For a point, the core distance is the distance to its k-th nearest neighbor, where k comes from the minimum samples setting. A point in a dense region has a small core distance; an isolated point has a large one.
Mutual reachability distance. The distance between two points is redefined using their core distances:
[ d_{mreach}(a,b) = \max\big(\mathrm{core}(a),\ \mathrm{core}(b),\ d(a,b)\big) ]
This transformation makes sparse points move farther apart from everything else, so they naturally separate as noise rather than forcing a cluster to reach out and grab them.
The five steps
The official documentation breaks the algorithm into a clear sequence:
- Transform the space. Convert the original distances into mutual reachability distances, which pushes low-density points away.
- Build a minimum spanning tree. Connect all points with the smallest total edge weight so every point is reachable, then treat edge weight as a measure of sparsity.
- Construct a cluster hierarchy. Sort the tree edges by distance and remove them longest first, recording how connected components split into a hierarchy.
- Condense the hierarchy. Use the minimum cluster size to prune branches that fall below it, so small, short-lived splits collapse into noise.
- Extract stable clusters. Walk the condensed tree and keep the clusters that persist across the widest range of density, measured by a cluster stability score.
The output is a set of labels, with points that never join a stable cluster marked as noise (typically label -1). Scikit-learn describes the same process using the minimum spanning tree and the greedy removal of the highest-weight edges.
HDBSCAN vs. DBSCAN vs. k-means
| HDBSCAN | DBSCAN | k-means | |
|---|---|---|---|
| Main parameter | Minimum cluster size | Epsilon and minimum samples | Number of clusters k |
| Fixed distance threshold | No | Yes | No (uses centroids) |
| Handles clusters of different density | Yes | Weakly | No |
| Shapes it can find | Arbitrary, non-spherical | Arbitrary, non-spherical | Mostly round, equal-sized |
| Number of clusters | Decided automatically | Decided by data and epsilon | Set in advance |
| Noise points | Explicitly labeled | Labeled | No built-in noise |
You can compare the parent method in the DBSCAN clustering guide and the centroid approach in k-means.
Parameters you actually tune
min_cluster_sizeThe smallest size a group can have to count as a cluster. Larger values merge more points and produce fewer, larger clusters. This is the one to adjust first.min_samplesControls how conservative the noise labeling is. Larger values mark more points as noise. When left unset, it usually follows the minimum cluster size.metricThe distance measure, such as Euclidean, or a precomputed distance matrix for custom data.
Unlike k-means, you do not set the number of clusters, which is helpful when you genuinely do not know how many groups exist.
When to use it
HDBSCAN is a sensible fit when:
- clusters have irregular shapes and uneven densities;
- you expect noise or outliers and want them flagged rather than forced into a group;
- you cannot state the number of clusters ahead of time;
- you can accept a higher computational cost than a simple partition method.
It is a less natural fit for very large datasets where speed dominates, or for data where clusters are clean, equally sized blobs that a simpler method already separates well. Because it is an unsupervised method, it belongs to the unsupervised learning family.
Frequently asked questions
Do I still need to pick epsilon in HDBSCAN? No. That is the main practical change from DBSCAN. HDBSCAN sweeps across density levels through its hierarchy, so you tune the minimum cluster size instead of a single radius.
Why does HDBSCAN label some points as noise? Points that sit in sparse regions and never belong to a stable cluster above the minimum size are assigned the noise label rather than attached to a nearby group. This keeps clusters from being stretched by outliers.
Is HDBSCAN slower than DBSCAN? Generally, yes. Building the minimum spanning tree and the hierarchy adds work, especially on large datasets. The trade-off is fewer assumptions about density and less sensitivity to a single threshold.
Can HDBSCAN find clusters of different densities in one dataset? Yes, that is one of its strengths. Because it reads stability across a hierarchy rather than applying one radius, it can keep a dense cluster and a separate loose cluster that DBSCAN would either merge or split.
Key takeaways
- HDBSCAN is a hierarchical, density-based method that keeps stable clusters and marks sparse points as noise.
- It replaces the fragile epsilon parameter with a minimum cluster size.
- Core and mutual reachability distances separate sparse points before clustering.
- A minimum spanning tree and a condensed hierarchy produce the final clusters.
- It suits irregular, variable-density data with outliers, at a higher cost than simpler methods.
For the surrounding vocabulary, see the machine learning glossary and the hierarchical clustering guide.
Sources
Learn by doing
Read a guide, then practice with bite-sized AI lessons you can take offline.
Start learning free