Semi-supervised HDBSCAN

Machine Learning
Introduced by
McInnes, L.; Healy, J. (base HDBSCAN); semi-supervised extensions by various authors
Year
2017–present
Type
Semi-supervised density-based clustering
Family
Machine learning

What does it do?

Semi-supervised HDBSCAN is not a single standard algorithm but a family of extensions to Hierarchical Density-Based Spatial Clustering of Applications with Noise (HDBSCAN) that add partial supervision, such as must-link and cannot-link pairwise constraints or a small set of labeled examples.

The aim is to steer the density-based cluster hierarchy toward assignments consistent with available domain knowledge. How the constraints are incorporated differs between implementations.

The intuition behind the method

HDBSCAN finds clusters of varying density without requiring the number of clusters to be specified in advance. In many applications, however, a practitioner knows that some pairs of points belong together, or that certain examples belong to known categories. Semi-supervised variants try to bring this side information into the process, for example by adjusting the mutual-reachability distances of constrained pairs before the hierarchy is built, or by using labels when selecting clusters from the tree. The intended result is a clustering that respects the density structure of the data and agrees with the partial labels where the two are compatible.

History

HDBSCAN extends DBSCAN by building a hierarchy of density levels and selecting clusters from that hierarchy. It was made widely available as a practical software package by McInnes, Healy, and Astels (2017), whose software paper is listed in the references. Pairwise-constraint clustering has an earlier history in constrained partitioning methods, such as constrained k-means variants. The semi-supervised HDBSCAN variants discussed here adapt these ideas to density-based clustering; no single canonical version is established, and the constraint-handling approach varies by implementation.

When to use it

Choose semi-supervised HDBSCAN when most of your data are unlabeled, the number of clusters is unknown, the clusters are expected to differ in density or shape, and you hold a small set of pairwise constraints or labeled examples that encode trustworthy domain knowledge. It is also suited to data in which noise and outliers are expected and should be separated from clusters. Avoid it when most observations are labeled, since a supervised classifier is then more appropriate. Avoid it for very small datasets, where density estimates are unreliable, and for very high-dimensional feature spaces that have not been reduced, because density estimates degrade as dimensionality grows. If the constraints are uncertain or contradictory, plain HDBSCAN is a safer starting point.

Limitations and considerations

  • Density estimation becomes unreliable in high-dimensional feature spaces, so dimensionality reduction is often needed first.
  • Constraint handling differs across implementations and is not standardized, which limits reproducibility across tools.
  • The minimum cluster size and related parameters still require domain judgement or a search over candidate values.
  • Soft or probabilistic label information is hard to encode, since constraints are typically hard must-link or cannot-link pairs.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Finds clusters of differing density and irregular shape without requiring the number of clusters to be set in advance.
  • Labels poorly fitting observations as noise rather than forcing every point into a cluster, which matters when outliers are expected.
  • Uses a small number of must-link or cannot-link constraints or labeled examples, so full annotation of the dataset is not required.
  • Selects clusters by persistence across density levels rather than by a single global radius as in DBSCAN. HDBSCAN, the base algorithm, uses this same persistence-based selection.
  • Can be applied after dimensionality reduction such as UMAP, and the base algorithm is available in the hdbscan Python package.

Applications

  • Bioinformatics: grouping cell populations in single-cell RNA-seq data with partial cell-type annotations.
  • Document and text clustering with a small set of known category examples to anchor the solution.
  • Anomaly detection pipelines where a few confirmed normal and anomalous examples guide cluster formation.
  • Geospatial analysis identifying regions of varying density with some labeled reference locations.
  • Customer segmentation when marketing teams can supply a handful of must-link and cannot-link pairs.

How it works

How it works

1

Mutual-reachability distances are computed as d_mreach(a,b) = max(core_k(a), core_k(b), d(a,b)), where core_k(x) is the distance from x to its k-th nearest neighbour. In the constrained variants described here, the distances of must-link pairs are reduced and those of cannot-link pairs are increased, biasing the graph toward or away from connecting those points. The exact adjustment is implementation-specific, and no single standard formula for it is established, so consult the documentation of the implementation you use.

2

A minimum spanning tree is built over the complete graph of mutual-reachability distances. Because constrained pairs have adjusted distances, they tend to join earlier or later in the tree. The adjustment is meant to guide the outcome, while the underlying density ordering of the data still determines most merges.

3

The minimum spanning tree is converted into a hierarchy by removing edges in decreasing order of weight, producing a dendrogram of nested splits. HDBSCAN then condenses this hierarchy by discarding splits that produce groups smaller than the minimum cluster size, which yields a tree of candidate clusters. The hierarchy encodes clustering at all density levels simultaneously.

4

Where labels or constraints are available, the candidate clusters in the condensed tree can be scored or filtered so that must-link pairs fall in the same cluster and cannot-link pairs do not. Before clustering, check the constraints for consistency: must-link is transitive, so points linked through a chain of must-link pairs form one group, and any cannot-link pair inside such a group is a contradiction. How strictly constraints are enforced depends on the implementation, and constraints that cannot all be satisfied together must be relaxed or rejected. Confirm how the implementation handles conflicts in its documentation.

5

A flat clustering is extracted by selecting the most persistent clusters, meaning those that survive across a wide range of density levels, and points not assigned to any selected cluster are labeled as noise. Standard HDBSCAN does not enforce user constraints in this step, so any constraint handling depends on the modified selection logic of the implementation.

Common pitfalls

  • Clustering very high-dimensional data without prior reduction, which produces density estimates that do not separate points well.
  • Treating the noise label (-1) as a real cluster when computing agreement with labels or summary statistics.
  • Supplying contradictory constraints, such as A must-link B and A cannot-link B, without checking consistency first.
  • Reading the clusters as ground-truth categories when the density structure does not match the domain taxonomy.
  • Reporting agreement with the labeled subset without checking that must-link pairs were co-clustered, or evaluating on the same points used to build the constraints, which inflates agreement.

Frequently asked questions

How do I incorporate must-link and cannot-link constraints in practice?

Implementations differ, so check the documentation of the one you use. A typical design, as outlined in the steps above, shrinks mutual-reachability distances for must-link pairs and enlarges them for cannot-link pairs before the minimum spanning tree is built. Some implementations instead, or in addition, filter the condensed cluster tree during extraction.

What if I only have a few labeled examples, not pairwise constraints?

Labeled examples can be converted to pairwise constraints: pairs sharing the same label become must-link pairs, and pairs with different labels become cannot-link pairs. The number of pairs grows quadratically with the number of labeled points, so apply this selectively to avoid an excess of constraints that overwhelms the density signal.

How does this differ from plain HDBSCAN?

Plain HDBSCAN is fully unsupervised and relies entirely on the data's density structure. Semi-supervised HDBSCAN biases the hierarchy using domain knowledge so the extracted clusters are more consistent with known groupings, at the cost of additional choices about constraint weighting and handling.

What evaluation metric should I use?

Evaluate against the labeled subset using adjusted Rand index (ARI) or normalized mutual information (NMI). Report the proportion of points labeled as noise and check that must-link pairs are co-clustered. Evaluate on points not used to build the constraints, otherwise agreement will be inflated.

Does semi-supervised HDBSCAN work in high dimensions?

Not reliably without preprocessing. Reduce dimensionality first with a method such as PCA or UMAP, and check that the density structure remains stable after reduction, because mutual-reachability distances become less informative as dimensionality grows.

Related methods

Sources

  1. McInnes, L., Healy, J., & Astels, S. (2017). hdbscan: Hierarchical density based clustering. Journal of Open Source Software, 2(11), 205.

    Open DOI reference
  2. HDBSCAN. Wikipedia.

    Open publication reference