# HDBSCAN

HDBSCAN（Hierarchical Density-Based Spatial Clustering of Applications with Noise，基于层次密度的带噪应用空间聚类）是一种基于密度的聚类算法，它构建基于密度的簇的层次结构，并从中提取最稳定的簇，将剩余的点标记为噪声。它在不同的 epsilon 值上执行 DBSCAN 并整合结果，以找到在 epsilon 上稳定性最佳的聚类，这使其能够发现不同密度的簇，并且比 DBSCAN 对参数选择更加稳健。<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup> 这些特性解释了为何它被采用为 BERTopic<sup>[2](https://maartengr.github.io/BERTopic/getting_started/clustering/clustering.html)</sup> 等主题建模流水线中的默认聚类步骤，也解释了其对噪声的稳健性：与 k-means、k-medoids 和高斯混合模型等基于质心的方法不同，它能够发现形状不规则、大小各异的簇。<sup>[3](https://developer.nvidia.com/blog/gpu-accelerated-hierarchical-dbscan-with-rapids-cuml-lets-get-back-to-the-future/)</sup>

| 关键事实 | 详情 |
|---|---|
| 输出 | 扁平标签（噪声为 −1，无穷值为 −2，缺失数据为 −3）、`probabilities_` 中的隶属强度、凝聚层次结构、GLOSH 离群点分数<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup><sup> • </sup><sup>[4](https://github.com/scikit-learn-contrib/hdbscan/tree/master/)</sup> |
| 核心度量 | 互达距离 \( \tilde{d}(x,y) = \max(d_{\mathrm{core}}(x), d_{\mathrm{core}}(y), d(x,y)) \)，旨在降低对离群点的敏感性<sup>[5](https://mlsys.org/Conferences/doc/2018/105.pdf)</sup> |
| 主要参数 | `min_cluster_size`（默认 5）、`min_samples`（默认为 `min_cluster_size`）、`cluster_selection_epsilon`、`max_cluster_size`<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup> |
| 复杂度 | 三个步骤的基线为 \( O(N^{2}) \)；加速版本平均情况接近 O(N log N)<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup> |
| GPU 加速 | 在 3M × 300 词嵌入基准上，cuML 约 22.8 分钟完成，而 CPU 实现在 24 小时后被中止<sup>[3](https://developer.nvidia.com/blog/gpu-accelerated-hierarchical-dbscan-with-rapids-cuml-lets-get-back-to-the-future/)</sup> |
| 离群点分数 | \( \mathrm{GLOSH}_{p} = (\lambda_{\max} - \lambda_{p})/\lambda_{\max} \)<sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup> |

## 工作原理

HDBSCAN 以到第 k 个最近邻的距离来廉价地估计密度，将其形式化为参数 k 的核心距离；密度是该距离的倒数，因此核心距离小意味着邻域密集。<sup>[8](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)</sup><sup> • </sup><sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup> 不同文献对具体索引约定存在分歧：一种将核心距离描述为到第 k 个最近邻的距离，其中 \( k = \mathrm{MinPts} - 1 \)（对象本身计入 MinPts）<sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup>，另一种将其定义为到第 minPts 个最近邻的距离。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup>

核心距离用于计算互达距离 \( \tilde{d}(x,y) = \max(d_{\mathrm{core}}(x), d_{\mathrm{core}}(y), d(x,y)) \)，其目的是通过将低密度区域的点彼此拉开，降低对离群点的敏感性。<sup>[5](https://mlsys.org/Conferences/doc/2018/105.pdf)</sup><sup> • </sup><sup>[8](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)</sup> 在该度量上计算最小生成树；其结果等价于按边权重递减顺序逐次切割的单链接层次聚类，从而产生连通分量的簇层次结构。<sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup><sup> • </sup><sup>[8](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)</sup> 与应用单一固定截断距离的 DBSCAN* 不同，HDBSCAN 为每个簇使用不同的临界截断距离来选择簇的最优组合。<sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup> 随后通过最小簇大小对层次结构进行凝聚，并通过簇稳定性提取簇：按逆拓扑顺序遍历凝聚树，当某个簇的稳定性超过其子簇稳定性之和时，保留该簇。<sup>[8](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)</sup> 这种质量超额（EOM）选择被推荐为寻找最高稳定性簇的最优全局方案。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup>

## 实现方法

实践者需运行五个步骤：根据密度变换空间、构建距离加权图的最小生成树、构建连通分量的簇层次结构、基于最小簇大小凝聚层次结构、提取稳定的簇。<sup>[8](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)</sup>

**参数。** `min_cluster_size` 是一组样本被视为一个簇所需的最小样本数；更小的分组被留作噪声。<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup> `min_samples` 是一个点被视为核心点所需的邻域样本数（包括该点本身），默认为 `min_cluster_size`。<sup>[10](http://sklearn.org/stable/auto_examples/cluster/plot_hdbscan.html)</sup> 较大的 `min_cluster_size` 值在具有高方差重叠簇的噪声数据集上往往更加稳健，而过小的值会导致虚假的子簇被优先选中；较大的 `min_samples` 增加对噪声的稳健性，但可能丢弃有效的小簇，应在调整 `min_cluster_size` 之后再行调整。<sup>[10](http://sklearn.org/stable/auto_examples/cluster/plot_hdbscan.html)</sup> `cluster_selection_epsilon` 是距离阈值，距离低于该阈值的簇会被合并，`max_cluster_size` 限制 EOM 选择方法返回的簇的大小。<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup> 选择也可以在凝聚树的叶节点上进行，而非通过 EOM。<sup>[11](https://docs.nvidia.com/cuml/26.08/api/generated/cuml.cluster.hdbscan.HDBSCAN/index.html)</sup>

**输出。** 噪声样本获得标签 −1，含无穷元素的样本为 −2，含缺失数据的样本为 −3；`probabilities_` 给出每个样本的簇隶属强度。<sup>[1](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)</sup> 隶属强度为 \( \lambda_{p}/\lambda_{\max} \)，GLOSH 离群点分数为其补数 \( 1 - \lambda_{p}/\lambda_{\max} \)；分数越高表示点越像离群点，建议通过上分位数选择离群点。<sup>[7](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)</sup><sup> • </sup><sup>[4](https://github.com/scikit-learn-contrib/hdbscan/tree/master/)</sup> 该库还支持对新点的预测和[软聚类](https://www.edgepedia.org/zh/soft-clustering)。<sup>[12](https://joss.theoj.org/papers/10.21105/joss.00205.pdf)</sup>

## 起源

HDBSCAN 建立在 DBSCAN* 之上，后者是一种将边界点声明为噪声的改进版 DBSCAN；HDBSCAN 针对 minPts 在所有 epsilon 值上创建层次结构。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup> 它是 DBSCAN* 的层次版本，类似于 OPTICS。<sup>[13](https://ar5iv.labs.arxiv.org/html/1702.08607)</sup> 原始论文《Density-Based Clustering Based on Hierarchical Density Estimates》提出了该方法，它生成完整的基于密度的聚类层次结构，可从中提取最重要簇的简化层次结构，同时提出了一种用于该提取的新簇稳定性度量。<sup>[14](https://page-one.springer.com/pdf/preview/10.1007/978-3-642-37456-2_14)</sup> 扩展的期刊版本《Hierarchical Density Estimates for Data Clustering, Visualization, and Outlier Detection》（ACM Transactions on Knowledge Discovery from Data，2015）由里卡多·J·G·B·坎佩洛（Ricardo J. G. B. Campello）及其同事撰写，引入了 GLOSH（Global-Local Outlier Scores from Hierarchies，基于层次结构的全局-局部离群点分数）。<sup>[15](https://doi.org/10.1145/2733381)</sup> 后续论文《Accelerated Hierarchical Density Based Clustering》重构了算法的计算核心。<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup>

## 变体

**加速版 HDBSCAN*。** 该加速算法利用空间树算法（kd 树、球树、覆盖树）进行最近邻核心距离查询，将三个二次步骤各自改进为平均情况复杂度接近 \( O(N \log N) \)。<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup> 它提供了与 DBSCAN 相当的性能，同时支持变密度簇并消除了难以调参的 epsilon 参数。<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup> 原始 HDBSCAN* 算法在 N 个点上的运行时间为 \( O(N^{2}) \)，包含三个二次步骤：核心距离与互达距离计算、最小生成树计算、树凝聚。<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup> 对于欧几里得度量下平面上的点，hdbscan 层次结构可在 \( O(n \log n) \) 期望时间内计算，而在 \( \mathbb{R}^{d} \) 中的 δ-近似层次结构可在 \( O((n/\delta^{(d-1)/2})\log n) \) 时间内计算。<sup>[13](https://ar5iv.labs.arxiv.org/html/1702.08607)</sup> 对于给定的点和参数，返回的簇是唯一的。<sup>[16](https://www.cs.ucr.edu/~ygu/papers/SIGMOD21/hdbscan.pdf)</sup>

**HDBSCAN(ε)。** 该变体对 HDBSCAN 簇层次结构应用额外阈值，可视为 DBSCAN* 与 HDBSCAN 的混合体，为固定 epsilon 选择 DBSCAN* 簇。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup>

**库实现。** Python 的 `hdbscan` 库还包含稳健单链接聚类和 GLOSH 离群点检测。<sup>[12](https://joss.theoj.org/papers/10.21105/joss.00205.pdf)</sup> scikit-learn 自带 `HDBSCAN`，近期开发工作添加了 Boruvka MST 后端，配有可配置的 `mst_algorithm` 参数和并行化的核心距离查询。<sup>[17](https://github.com/scikit-learn/scikit-learn/pull/33364)</sup> RAPIDS cuML 提供 GPU 实现，使用 FAISS 暴力 kNN 加速互达距离空间中的 kNN 图构建，这是一个主要瓶颈。<sup>[3](https://developer.nvidia.com/blog/gpu-accelerated-hierarchical-dbscan-with-rapids-cuml-lets-get-back-to-the-future/)</sup> 对于流式和多密度场景，纳塔纳埃尔·F·D·巴蒂斯塔（Natanael F. D. Batista）、布鲁诺·L·努内斯（Bruno L. Nunes）和穆里洛·C·纳尔迪（Murilo C. Naldi）提出了 CORE-SG（一种用于快速 HDBSCAN* 计算的生成图，Applied Soft Computing，2025）；它通过数据抽象减少了邻域估计步骤（其成对相似度计算受二次渐近复杂度约束），并在数据流上与最新的基于 HDBSCAN* 的算法进行了基准测试，表现出更优的性能和更好的聚类质量。<sup>[18](https://doi.org/10.1016/j.asoc.2025.114019)</sup><sup> • </sup><sup>[19](http://dl.acm.org/doi/10.1016/j.asoc.2025.114019)</sup>

## 应用

BERTopic 使用 HDBSCAN 作为其默认聚类步骤。k-means 可以替代，但它强制每个点归入某个簇，很可能包括损害最终主题表示的噪声；HDBSCAN 能够将噪声保持未标记，避免了这一问题。<sup>[2](https://maartengr.github.io/BERTopic/getting_started/clustering/clustering.html)</sup> cuML 的 GPU 加速 HDBSCAN 可在 BERTopic 内部使用，以加速大数据上的聚类。<sup>[2](https://maartengr.github.io/BERTopic/getting_started/clustering/clustering.html)</sup> HDBSCAN* 还作为一个统计上可靠的框架的核心算法，该框架由基于密度的聚类构建模块构成，用于[半监督聚类](https://www.edgepedia.org/zh/semi-supervised-clustering)和分类，并推广到了无监督聚类之外。<sup>[20](https://dl.acm.org/doi/10.1007/s10618-019-00651-1)</sup>

## 局限与替代方案

在密度高度变化的数据集中，特别是选择较低的最小簇大小时，HDBSCAN 可能完全遗漏潜在相关的簇，或在高密度区域返回大量小簇。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup> HDBSCAN(ε) 通过向层次结构添加密度阈值来解决这一问题。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup> 与 DBSCAN 相比，HDBSCAN 消除了敏感的 epsilon 参数并处理变密度，且单次 HDBSCAN* 运行允许用户提取任意给定 epsilon 下的 DBSCAN 聚类。<sup>[6](https://arxiv.org/pdf/1705.07321v2)</sup> HDBSCAN 已被证明优于 AUTO-HDS 以及 OPTICS 与桑德（Sander）等人的簇提取方法的组合。<sup>[9](https://arxiv.org/pdf/1911.02282)</sup> 与 k-means 相比，一位基准测试作者推荐将 HDBSCAN 用于一般聚类，因为它聚类效果更好（除非已知簇为高斯划分），且其扩展性仍然相当好，除非数据量真正巨大。<sup>[21](https://hdbscan.readthedocs.io/en/latest/performance_and_scalability.html)</sup> 高维数据会降低扩展性能。<sup>[21](https://hdbscan.readthedocs.io/en/latest/performance_and_scalability.html)</sup> 实现很重要：Python `hdbscan` 包比参考 Java [实现](https://www.edgepedia.org/zh/implementation)快数个数量级，也比高度优化的 C 和 C++ 单链接实现更快。<sup>[4](https://github.com/scikit-learn-contrib/hdbscan/tree/master/)</sup>

## References

1. [HDBSCAN, scikit-learn 1.9.0 documentation](https://scikit-learn.org/stable/modules/generated/sklearn.cluster.HDBSCAN.html)
2. [Clustering, BERTopic documentation](https://maartengr.github.io/BERTopic/getting_started/clustering/clustering.html)
3. [GPU-Accelerated Hierarchical DBSCAN with RAPIDS cuML (NVIDIA Technical Blog)](https://developer.nvidia.com/blog/gpu-accelerated-hierarchical-dbscan-with-rapids-cuml-lets-get-back-to-the-future/)
4. [GitHub - scikit-learn-contrib/hdbscan (README)](https://github.com/scikit-learn-contrib/hdbscan/tree/master/)
5. [Scaling HDBSCAN Clustering with kNN Graph Approximation (MLSys 2018)](https://mlsys.org/Conferences/doc/2018/105.pdf)
6. [Accelerated Hierarchical Density Based Clustering (McInnes, Healy; arXiv:1705.07321, IEEE ICDMW 2017)](https://arxiv.org/pdf/1705.07321v2)
7. [20.5 HDBSCAN | An Introduction to Spatial Data Science with GeoDa (Selin)](https://lanselin.github.io/introbook_vol1/HDBSCAN.html)
8. [How HDBSCAN Works, hdbscan library documentation](https://hdbscan.readthedocs.io/en/latest/how%5Fhdbscan%5Fworks.html)
9. [HDBSCAN(ε), a parameter-free alternative to HDBSCAN (arXiv:1911.02282)](https://arxiv.org/pdf/1911.02282)
10. [Demo of HDBSCAN clustering algorithm, scikit-learn](http://sklearn.org/stable/auto_examples/cluster/plot_hdbscan.html)
11. [HDBSCAN, NVIDIA cuML API documentation (26.08)](https://docs.nvidia.com/cuml/26.08/api/generated/cuml.cluster.hdbscan.HDBSCAN/index.html)
12. [hdbscan: Hierarchical density based clustering (JOSS software paper, McInnes et al.)](https://joss.theoj.org/papers/10.21105/joss.00205.pdf)
13. [Faster DBSCAN and HDBSCAN in Low-Dimensional Euclidean Spaces (arXiv:1702.08607)](https://ar5iv.labs.arxiv.org/html/1702.08607)
14. [Density-Based Clustering Based on Hierarchical Density Estimates (Campello, Moulavi, Sander, Springer chapter preview)](https://page-one.springer.com/pdf/preview/10.1007/978-3-642-37456-2_14)
15. [Ricardo J. G. B. Campello and colleagues (2015). Hierarchical Density Estimates for Data Clustering, Visualization, and Outlier Detection. ACM Transactions on Knowledge Discovery from Data.](https://doi.org/10.1145/2733381)
16. [Fast Parallel Algorithms for Euclidean Minimum Spanning Tree and Hierarchical Spatial Clustering (SIGMOD 2021)](https://www.cs.ucr.edu/~ygu/papers/SIGMOD21/hdbscan.pdf)
17. [ENH HDBSCAN: add Boruvka MST backend and parallel core-distance queries (scikit-learn PR)](https://github.com/scikit-learn/scikit-learn/pull/33364)
18. [Natanael F.D. Batista, Bruno L. Nunes, Murilo C. Naldi (2025). Efficient multiple density-based models over large datasets with data stream applications. Applied Soft Computing.](https://doi.org/10.1016/j.asoc.2025.114019)
19. [Efficient multiple density-based models over large datasets with data stream applications (Applied Soft Computing, 2025)](http://dl.acm.org/doi/10.1016/j.asoc.2025.114019)
20. [A unified view of density-based methods for semi-supervised clustering and classification (Data Mining and Knowledge Discovery)](https://dl.acm.org/doi/10.1007/s10618-019-00651-1)
21. [Benchmarking Performance and Scaling of Python Clustering Algorithms, hdbscan documentation](https://hdbscan.readthedocs.io/en/latest/performance_and_scalability.html)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Clustering algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hdbscan

English original: https://www.edgepedia.org/hdbscan
