HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is an unsupervised learning algorithm that performs density-based clustering by building a hierarchy of all possible density-based clusters. Unlike its predecessor DBSCAN, which requires a fixed eps distance parameter, HDBSCAN automatically identifies clusters of varying densities by analyzing the stability of clusters across different density thresholds. The algorithm constructs a minimum spanning tree in mutual reachability distance space, then condenses it into a cluster hierarchy, extracting the most persistent and stable clusters as the final flat solution.
Glossary
HDBSCAN

What is HDBSCAN?
HDBSCAN is a hierarchical density-based clustering algorithm that extends DBSCAN by constructing a cluster hierarchy and extracting the most stable flat clustering, robustly handling varying density clusters without requiring a distance threshold.
The core innovation of HDBSCAN lies in its cluster stability metric, which measures the relative excess of mass of a cluster over its lifetime in the hierarchy. This allows the algorithm to distinguish genuine clusters from noise without requiring the user to specify a global density cutoff. Points not assigned to any stable cluster are classified as noise, making HDBSCAN particularly effective for patient stratification tasks where outlier patients, transitional disease states, and subpopulations of varying sizes and densities must be identified from high-dimensional molecular data without imposing arbitrary cluster counts.
Key Features of HDBSCAN
HDBSCAN extends DBSCAN by converting the problem into a hierarchical clustering task, then extracting a flat clustering based on the stability of clusters. This allows it to find clusters of varying densities without needing to specify the eps distance threshold, making it ideal for complex, high-dimensional biomedical data.
Robustness to Varying Densities
The core innovation of HDBSCAN is its ability to identify clusters with significantly different densities within the same dataset. Unlike DBSCAN, which uses a global density threshold (eps), HDBSCAN builds a hierarchy over all possible eps values. It then uses a cluster stability metric to select the most persistent clusters across the hierarchy, naturally accommodating both dense and sparse regions without parameter tuning.
Soft Clustering & Outlier Detection
HDBSCAN provides a membership probability for each point, quantifying how strongly a point belongs to its assigned cluster. This soft clustering is derived from the point's distance to the cluster's core. Points with low probability are robustly classified as noise or outliers, a critical feature for identifying anomalous patient profiles or data artifacts in biomarker discovery pipelines.
Minimum Cluster Size Parameter
The primary hyperparameter is min_cluster_size, which specifies the smallest grouping to be considered a cluster. This is highly intuitive for patient stratification, where a clinician can specify the minimum number of patients required to define a clinically meaningful subgroup. This single parameter replaces DBSCAN's eps and min_samples, dramatically simplifying model selection.
Mutual Reachability Distance
HDBSCAN constructs a mutual reachability graph using a novel distance metric. The mutual reachability distance between two points is the maximum of: the core distance of point A, the core distance of point B, and the original distance between them. This effectively pushes apart points in sparse regions, making the separation between dense clusters and noise more pronounced and robust.
Condensed Cluster Tree Extraction
After building a full single-linkage hierarchy, HDBSCAN computes a minimum spanning tree on the mutual reachability graph and converts it into a dendrogram. It then condenses this tree by pruning small, unstable splits. The algorithm traverses the condensed tree and selects flat clusters that maximize the sum of relative excess of mass (stability), providing an optimal, data-driven cut.
Benchmarking Against UMAP & t-SNE
HDBSCAN is frequently paired with UMAP for dimensionality reduction before clustering, as UMAP preserves more global structure than t-SNE. In single-cell RNA sequencing workflows, the combination of UMAP for visualization and HDBSCAN for clustering has become a standard pipeline, often outperforming Louvain or Leiden community detection in identifying rare cell populations and transitional states.
Frequently Asked Questions
Clear, technical answers to the most common questions about Hierarchical Density-Based Spatial Clustering of Applications with Noise and its role in patient stratification.
HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is an unsupervised clustering algorithm that extends DBSCAN by converting it into a hierarchical clustering framework and then extracting a flat, optimized clustering based on the relative stability of clusters. The algorithm works by first constructing a mutual reachability graph that redefines the distance between points based on their local density, effectively normalizing for varying density regions. It then builds a minimum spanning tree from this graph and constructs a hierarchy of clusters by iteratively removing edges in descending order of weight. Finally, it selects the most persistent clusters from this hierarchy by optimizing for excess of mass, a measure of cluster stability over the lifetime of the hierarchy. This process allows HDBSCAN to identify clusters of varying shapes and densities while automatically classifying sparse points as noise, all without requiring the user to pre-specify the number of clusters.
HDBSCAN vs. DBSCAN vs. OPTICS
A technical comparison of three density-based clustering algorithms for patient stratification, evaluating their handling of varying density clusters, parameter sensitivity, and scalability.
| Feature | HDBSCAN | DBSCAN | OPTICS |
|---|---|---|---|
Core Algorithm | Hierarchical density-based clustering with cluster stability extraction | Density-based spatial clustering with fixed epsilon neighborhood | Ordering points to identify the clustering structure across all epsilon values |
Varying Density Handling | |||
Flat Cluster Output | |||
Hierarchical Output | |||
Global Density Threshold (ε) | |||
Minimum Cluster Size Parameter | |||
Outlier/Noise Detection | |||
Computational Complexity | O(n log n) | O(n log n) with spatial indexing | O(n log n) with spatial indexing |
Soft Clustering (Membership Probability) | |||
Deterministic Results | |||
Scalability to High-Dimensional Data | Moderate (requires dimensionality reduction) | Poor (curse of dimensionality) | Poor (curse of dimensionality) |
Python Implementation | hdbscan library | scikit-learn | scikit-learn |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Applications in Precision Medicine
HDBSCAN's ability to identify clusters of varying density and label outliers as noise makes it exceptionally well-suited for discovering novel disease subtypes and rare cell populations in high-dimensional biomedical data.
Endotype Discovery in Heterogeneous Diseases
HDBSCAN excels at identifying clinically meaningful disease subtypes (endotypes) from complex patient data without requiring a pre-specified number of clusters. Unlike centroid-based methods, it naturally handles the varying densities of patient subgroups—common in conditions like asthma or sepsis where a large, diffuse group of mild patients coexists with a small, dense cluster of severe patients. The algorithm's outlier detection capability is critical here, as it prevents forcing every patient into a cluster, instead flagging individuals with unique molecular profiles for further clinical review. This aligns with the biological reality that not all patients fit neatly into a single subtype.
Single-Cell RNA Sequencing Analysis
In single-cell transcriptomics, HDBSCAN is a powerful tool for identifying discrete cell types and transient cell states. Its density-based logic naturally separates rare cell populations from abundant ones without the need for post-hoc filtering. Key advantages include:
- Variable density handling: Distinguishes a small, dense cluster of activated T-cells from a large, diffuse cluster of resting lymphocytes.
- Hierarchical output: The condensed tree allows researchers to explore cell populations at multiple levels of granularity, from broad lineages to fine subtypes.
- Noise robustness: Technical dropout events in scRNA-seq data create sparse regions; HDBSCAN correctly labels these as noise rather than forcing them into spurious clusters.
Digital Pathology and Spatial Biology
HDBSCAN is applied to spatial transcriptomics and multiplexed imaging data to identify spatially coherent tissue domains and cellular neighborhoods. By clustering cells based on both their molecular profiles and spatial coordinates, HDBSCAN reveals the tissue architecture underlying disease. For example, in oncology, it can delineate the tumor core, invasive margin, and immune-excluded stroma as distinct spatial clusters. The algorithm's ability to find clusters of arbitrary shape is essential here, as biological structures like tumor buds or tertiary lymphoid structures are rarely spherical in feature space.
Patient Similarity Network Construction
HDBSCAN can be used to cluster nodes in patient similarity networks, where edges represent clinical or molecular similarity between individuals. After constructing a graph using methods like Similarity Network Fusion (SNF), HDBSCAN operates on the network's distance matrix to identify communities of phenotypically similar patients. This approach is particularly effective for:
- Multi-omics integration: Clustering patients based on fused similarity across genomics, proteomics, and imaging data.
- Rare disease cohort identification: Finding small, tight-knit groups of patients sharing a cryptic molecular signature within a large, heterogeneous registry. The minimum cluster size parameter provides direct control over the granularity of the stratification.
Rare Cell and Biomarker Detection
The outlier persistence concept in HDBSCAN makes it a natural choice for anomaly detection in clinical flow cytometry and mass cytometry (CyTOF) data. Instead of requiring a separate one-class classifier, HDBSCAN simultaneously clusters the major cell populations and flags rare events. This is critical for:
- Minimal Residual Disease (MRD) monitoring: Identifying a tiny cluster of leukemic cells among millions of normal hematopoietic cells.
- Biomarker discovery: Detecting a small, dense cluster of patients with an extreme response to therapy, whose shared molecular features can be investigated as predictive biomarkers. The GLOSH outlier score provides a continuous measure of how anomalous each data point is.
Longitudinal Disease Trajectory Modeling
By applying HDBSCAN to time-series clinical data, researchers can identify distinct disease progression trajectories. After extracting features that capture the rate of change in lab values or symptoms, HDBSCAN clusters patients into groups such as 'rapid progressors,' 'slow progressors,' and 'stable.' The algorithm's robustness to noise is vital here, as transient fluctuations in biomarkers do not derail the clustering. The condensed tree visualization allows clinicians to see how trajectory clusters merge at different stability thresholds, providing insight into the hierarchical relationship between different progression patterns.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us