HDBSCAN
clustering
machine learning
data analysis
algorithm parameters

HDBSCAN difference between parameters

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) is an advanced clustering algorithm that extends the DBSCAN (Density-Based Spatial Clustering of Applications with Noise) algorithm to produce a hierarchy of clusters. The key advantage of HDBSCAN over DBSCAN is its ability to handle varying densities and its robustness to noise. This article provides an in-depth examination of the various parameters in HDBSCAN and their impacts on clustering outcomes, along with technical explanations and examples.

HDBSCAN `Parameters`

HDBSCAN has several critical parameters that influence its clustering behavior:

  1. `min_cluster_size`: This parameter defines the minimum size of clusters.
  2. `min_samples`: Essentially a density factor, this parameter determines how conservative the clustering will be.
  3. `cluster_selection_epsilon`: Helps define the flat clustering by providing a cut across the cluster hierarchy.
  4. `cluster_selection_method`: Determines how clusters are selected from the cluster hierarchy.
  5. `metric`: Determines the distance metric used.
  6. `alpha`: Controls the balance between connectivity and density.
  7. `core_dist_n_jobs`: Determines how many parallel jobs to run for core distance calculations.

Detailed Explanation of `Parameters`

`min_cluster_size`

The `min_cluster_size` is one of the most critical parameters because it directly affects the size of the clusters generated. It sets the minimum membership count a cluster needs to be considered valid.

  • Technical Explanation: If `min_cluster_size` is set to 5, then the smallest cluster can have 5 data points. Clusters with fewer points will be treated as noise.
  • Example: Imagine a dataset with several tightly grouped points and some distant outliers. Setting `min_cluster_size` to 1 might treat outliers as valid clusters, while increasing it to 5 could correctly label those outliers as noise.

`min_samples`

The `min_samples` parameter affects the stability of clusters by modifying how density is calculated. A higher `min_samples` value results in more conservative clusters, as more points are required to form a core point.

  • Technical Explanation: A point is considered a core point if there are at least `min_samples` within its neighborhood. This number plays a crucial role in determining which points make up dense regions.
  • Example: Increasing `min_samples` will often result in larger and fewer clusters, merging sparsely populated regions and emphasizing more densely-packed clusters.

`cluster_selection_epsilon`

`cluster_selection_epsilon` is used for controlling the strictness of the clustering. It operates as a horizontal cut in the cluster hierarchy, affecting the flat clustering output.

  • Technical Explanation: It helps facilitate cluster extraction through cutting the dendrogram (output of HDBSCAN's hierarchical approach) at a certain density level.
  • Example: With a small `cluster_selection_epsilon`, HDBSCAN might find smaller and tighter clusters by ignoring lower-density areas.

`cluster_selection_method`

There are two ways to select clusters from the HDBSCAN hierarchy: `'leaf'` and `'eom'` (excess of mass).

  • Technical Explanation:
    • `'leaf'`: Focuses on finding leaf clusters in the dendrogram, typically resulting in finer clustering.
    • `'eom'`: Utilizes a flatter selection method, often yielding coarser clusters from higher up in the dendrogram.
  • Example: In applications like image segmentation, where finer granularity is required, `'leaf'` may be preferred. In contrast, for general data analysis purposes, `'eom'` offers robustness and interpretability.

`metric`

The `metric` parameter determines how distances between data points are calculated.

  • Technical Explanation: By default, HDBSCAN uses the Euclidean distance, but it can be altered to any appropriate distance metric, such as Manhattan or cosine.
  • Example: In spaces where dimensions have varying scales, selecting an appropriate metric like Manhattan may produce better clustering results.

`alpha`

This parameter adjusts the emphasis between connectivity and density components.

  • Technical Explanation: A higher `alpha` increases the relative importance of density over connectivity.
  • Example: Setting a very high `alpha` can result in stricter clusters, placing more emphasis on density than the path connectivity.

`core_dist_n_jobs`

Specifies the number of parallel computations used for core distance processing, enhancing performance with large datasets.

  • Technical Explanation: The parallelization is done through scikit-learn's support for the `n_jobs` parameter.
  • Example: On a multicore machine, setting `core_dist_n_jobs` to `-1` can significantly reduce computation time by utilizing all available cores.

Summary Table

Below is a table summarizing key differences:

ParameterDescriptionImpact on Clustering
min\_cluster\_sizeMinimum number of points per clusterControls the size and existence of clusters
min\_samplesPoints needed to consider a location as denseAffects stability and density requirements
cluster\_selection\_epsilonDefines the density level for flat clusteringAdjusts granularity of the output clusters
cluster\_selection\_methodMethod for deriving clusters from the hierarchyInfluences cluster resolution
metricDistance metric for calculating distancesAlters spatial interpretation of points
alphaBalances between connectivity and densityModifies cluster compactness
core\_dist\_n\_jobsNumber of jobs for parallel computationEnhances performance

Conclusion

HDBSCAN is a robust and versatile clustering algorithm well-suited for a variety of datasets, especially those with uneven densities and noise. Understanding and configuring its parameters effectively can make a significant difference in obtaining meaningful clusters that accurately capture the underlying structure of your data. As with any clustering problem, domain knowledge, combined with parameter tuning, is essential for deriving the best results.


Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.