HDBSCAN聚类
计算公式
符号
| 符号 | 含义 |
|---|---|
| d(·,·) | 样本间的距离 |
| k | 密度估计的邻域点数 |
| dcore,k(x) | 样本 x 到第 k 近邻的距离(核心距离) |
| dmreach(·,·) | 互达距离 |
| λ | 密度水平,λ = 1 / 互达距离 |
| S(C) | 簇 C 的稳定性 |
| m | 最小簇样本数 |
核心公式
公式 (1.1):核心距离
\[
d_{\mathrm{core},k}(x_i)=d\left(x_i,x_{(k)}\right)
\]
公式 (1.2):互达距离
\[
d_{\mathrm{mreach}}(x_i,x_j)=\max\left\{d_{\mathrm{core},k}(x_i),\,d_{\mathrm{core},k}(x_j),\,d(x_i,x_j)\right\}
\]
公式 (1.3):簇稳定性与剪枝
\[
S(C)=\sum_{x_i\in C}\left(\lambda_i-\lambda_{\mathrm{birth}}(C)\right),\qquad \hat{\mathcal{C}}=\arg\max_{\mathcal{C}\subseteq\mathcal{T}}\sum_{C\in\mathcal{C}}S(C)
\]
公式 (1.4):平均轮廓系数(仅非噪声样本)
\[
s(i)=\frac{b(i)-a(i)}{\max\{a(i),b(i)\}},\qquad \bar{s}=\frac{1}{|\{i:c_i\ne -1\}|}\sum_{i:\,c_i\ne -1}s(i)
\]
参考文献
- Campello, R. J. G. B., Moulavi, D., & Sander, J. (2013). Density-based clustering based on hierarchical density estimates. In Advances in Knowledge Discovery and Data Mining (LNCS 7819, pp. 160–172). Springer.
- McInnes, L., Healy, J., & Astels, S. (2017). hdbscan: Hierarchical density based clustering. Journal of Open Source Software, 2(11), 205.
- Schubert, E., Sander, J., Ester, M., Kriegel, H.-P., & Xu, X. (2017). DBSCAN revisited, revisited: Why and how you should (still) use DBSCAN. ACM Transactions on Database Systems, 42(3), Article 19.
算法参数
| 参数 | 取值 | 默认 | 影响 |
|---|---|---|---|
| 最小簇样本数 | 2 到有效样本数 | 5 | 小于该数的密集群不单独成簇,通常并入邻近簇或判为噪声。 |
| 密度估计邻域点数 | 1 到有效样本数 | 等于最小簇样本数 | 越大密度估计越保守,噪声越多、簇越少;取 1 时每个点都可作核心点。 |
| 标准化 | 是 / 否 | 是 | 对参与聚类的变量做 z 标准化;不标准化时大量纲变量会主导距离。 |
验证报告
数据与 R 包
提示词
对 X1、X2 做 HDBSCAN 层次密度聚类:先标准化,最小簇样本数设为 5,密度估计邻域点数设为 5;输出簇数、噪声、各簇样本量与平均轮廓系数。
R 代码
library(dbscan)
library(cluster)
d <- read.csv("hdbscan.csv")
x <- scale(d[, c("X1", "X2")])
n <- nrow(x)
xs <- x * sqrt((n - 1) / n) # 总体标准差,与 SPSSAU 一致
fit <- hdbscan(xs, minPts = 5)
print(sort(table(fit$cluster), decreasing = TRUE))
keep <- fit$cluster != 0
s <- silhouette(fit$cluster[keep], dist(xs[keep, ]))
cat("silhouette", mean(s[, 3]), "\n")
cat("membership", mean(fit$membership_prob[keep]), "\n")
对比结果
| 指标 | SPSSAU | R | 差值 |
|---|---|---|---|
| 有效样本数 | 110 | 110 | 0 |
| 簇数(不含噪声) | 3 | 3 | 0 |
| 噪声样本数 | 14 | 14 | 0 |
| 聚类1 样本量 | 67 | 67 | 0 |
| 聚类2 样本量 | 20 | 20 | 0 |
| 聚类3 样本量 | 9 | 9 | 0 |
| 平均轮廓系数(非噪声) | 0.6091066089 | 0.6091066089 | 4.69e−11 |
| 平均簇归属概率(非噪声,口径不同) | 0.8723665958 | 0.5279603834 | 0.344 |
结论:簇数(3)、三簇样本量(67/20/9)、噪声数(14)与平均轮廓系数均与 R 的 dbscan 包 hdbscan 函数一致,轮廓系数最大差 4.7e−11。平均簇归属概率差异较大(0.8724 vs 0.5280),因为 SPSSAU 与 R 包对归属概率的定义不同,属于口径差异,不改变簇划分。
引用SPSSAU. HDBSCAN聚类:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/advanced/hdbscan.html.