Inferensys

Glossary

HDBSCAN

HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is an unsupervised learning algorithm that extends DBSCAN by converting it into a hierarchical clustering algorithm and then extracting a flat, optimized clustering based on cluster stability.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
HIERARCHICAL DENSITY-BASED CLUSTERING

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.

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.

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.

DENSITY-BASED HIERARCHICAL CLUSTERING

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.

01

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.

02

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.

03

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.

04

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.

05

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.

06

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.

HDBSCAN CLUSTERING EXPLAINED

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.

DENSITY-BASED CLUSTERING COMPARISON

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.

FeatureHDBSCANDBSCANOPTICS

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

HDBSCAN IN BIOMEDICAL RESEARCH

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.

01

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.

Noise Points
Identifies atypical patients as outliers
02

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.
03

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.

04

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.
05

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.
06

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.

Prasad Kumkar

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.