# 密度估计

密度估计是从观测数据中恢复随机变量概率密度函数 \( f \) 的统计任务；非参数密度估计则是在不对 \( f \) 假定固定参数形式的前提下完成这一任务。各类方法可分为参数方法与非参数方法：参数方法通过最大似然拟合某一分布族，如有限混合模型；非参数方法主要有直方图与核密度估计（KDE），由数据本身决定密度的形状。<sup>[1](https://ned.ipac.caltech.edu/level5/March02/Silverman/paper.pdf)</sup>

| 关键事实 | 内容 |
|---|---|
| 核估计 | \( \hat{f}_h(x) = \frac{1}{n \cdot h} \sum_{i=1}^{n} K\!\left( \frac{x - X_i}{h} \right) \)；带宽 \( h \) 至关重要，核的形状在实际中影响甚微<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup> |
| Silverman 经验法则 | \( h_{\mathrm{SROT}} = 0.9 \cdot A \cdot n^{-1/5} \)，其中 \( A = \min\{ \text{样本标准差}, \text{样本四分位距}/1.34 \} \)<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup> |
| 偏差比较 | 直方图的偏差为 \( h \) 阶；在每个数据点处放置对称核，可将主导偏差降至 \( h^2 \) 阶<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup> |
| 极小极大平方 \( L_2 \) 误差 | 在 \( d \) 维下为 \( n^{-4/(4+d)} \)，而参数速率为 \( d/n \)<sup>[3](https://proceedings.mlr.press/v54/mcdonald17a/mcdonald17a.pdf)</sup> |
| 带宽选择器的收敛速度 | 交叉验证选择器为 \( n^{1/10} \)；Sheather–Jones 插入法为 \( n^{5/14} \)<sup>[4](https://egarpor.github.io/NP-EAFIT/dens-bwd.html)</sup> |
| 分数去偏 KDE（2025） | AMISE 为 \( O(n^{-8/(d+8)}) \)，而标准 KDE 为 \( O(n^{-4/(d+4)}) \)<sup>[5](https://papers.nips.cc/paper_files/paper/2025/file/fd8548947a14f68375d7e6235ab493ec-Paper-Conference.pdf)</sup> |
| 软件 | scikit-learn 的 `KernelDensity`（六种核，Ball Tree/KD Tree）；R 的 `density()` 及 `bw.nrd0`、`bw.SJ`；`ks::kde()`；SAS PROC KDE<sup>[6](https://scikit-learn.org/stable/modules/density.html)</sup><sup> • </sup><sup>[7](https://cswr.nrhstat.org/density)</sup><sup> • </sup><sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup> |

## 工作原理

核估计在每个观测点处放置一个光滑函数——核 \( K \)——的缩放副本，再对它们取平均：\( \hat{f}_h(x) = \frac{1}{n \cdot h} \sum_{i=1}^{n} K\!\left( \frac{x - X_i}{h} \right) \)。核决定这些“小丘”的形状，窗宽 \( h \) 决定它们的宽度。<sup>[1](https://ned.ipac.caltech.edu/level5/March02/Silverman/paper.pdf)</sup> 等价地说，该估计是以数据点为中心、形状相近的 \( n \) 个密度的等概率混合。<sup>[8](https://luc.devroye.org/Devroye-ACourseInDensityEstimation-1987.pdf)</sup>

带宽的影响远大于核的选择。已发表的比较一致认为，\( h \) 的取值至关重要，而核的形状在实际中影响甚微；高斯核是标准选择，可得到无穷次可微的估计。<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup><sup> • </sup><sup>[7](https://cswr.nrhstat.org/density)</sup> 原因在于偏差–方差权衡。箱宽为 \( h \) 的直方图，其偏差为 \( h \) 阶；在每个数据点处放置对称核可抵消该项，使主导偏差降为 \( h^2 \) 阶，而方差约为 \( 1/(n \cdot h) \)。<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup> 渐近最优的积分均方误差可分解为 \( \mathrm{AMISE}(\hat{f}(\cdot;h)) = \frac{1}{4} \mu_2(K)^2 R(f'') \cdot h^4 + \frac{R(K)}{n \cdot h} \)，其中 \( R(f'') = \int (f''(x))^2 \, dx \) 未知，因而必须加以估计。<sup>[4](https://egarpor.github.io/NP-EAFIT/dens-bwd.html)</sup>

## 操作步骤

1. 选择路线：快速浏览用直方图，需要光滑估计用 KDE，需要紧凑的参数摘要时用混合模型。
2. 选取核（默认为高斯核）与带宽。Silverman 经验法则 \( h_{\mathrm{SROT}} = 0.9 \cdot A \cdot n^{-1/5} \)，其中 \( A = \min\{ \text{样本标准差}, \text{样本四分位距}/1.34 \} \)，是 R 通过 `bw.nrd0()` 给出的默认值；而朴素正态参考法则 \( h = 1.06 \cdot S \cdot n^{-1/5} \) 被发现通常过大、难以接受，Silverman 法则则已知会对多峰密度造成过度平滑。<sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup><sup> • </sup><sup>[7](https://cswr.nrhstat.org/density)</sup>
3. 若采用数据驱动选择，可使用最小二乘交叉验证（最小化留一准则）、有偏交叉验证或插入法选择器。Sheather–Jones 直接插入法的收敛速度为 \( n^{5/14} \)，远快于交叉验证选择器的 \( n^{1/10} \)，被视为稳妥的默认方法。<sup>[4](https://egarpor.github.io/NP-EAFIT/dens-bwd.html)</sup><sup> • </sup><sup>[9](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1991.tb01857.x)</sup><sup> • </sup><sup>[2](https://eliassi.org/Sheather_StatSci_2004.pdf)</sup>
4. 若支撑集有界，需处理边界：可选做法包括不作处理、对数据取对数变换、数据反射、边界核、局部似然，或除以边缘校正因子 \( w_h(x_i) = \int_a^b K_h(x_i - x) \, dx \)。<sup>[10](https://www.stat.cmu.edu/~larry/=sml/densityestimation.pdf)</sup><sup> • </sup><sup>[11](https://mdporter.github.io/SYS6018/lectures/density.pdf)</sup>
5. 计算并验证。在 R 中，`density()` 配合 `bw = "sj"` 即使用 Sheather–Jones 选择器，也可通过 `bw.SJ()` 调用；`ks` 包的 `kde()` 支持多变量 KDE，并提供 `hpi()`、`hlscv()`、`hscv()`、`hucv()` 等选择器。<sup>[7](https://cswr.nrhstat.org/density)</sup><sup> • </sup><sup>[11](https://mdporter.github.io/SYS6018/lectures/density.pdf)</sup> scikit-learn 的 `KernelDensity` 实现了 高斯核、顶帽核、Epanechnikov 核、指数核、线性核与余弦核六种核，使用 Ball Tree 或 KD Tree 进行高效查询，可接受斯科特或 Silverman 带宽，也可手动指定数值。<sup>[6](https://scikit-learn.org/stable/modules/density.html)</sup>

## 起源

第一篇明确讨论密度估计的已发表论文是 默里·罗森布拉特（Murray Rosenblatt）的《关于密度函数某些非参数估计的注记》（《数学统计年鉴》，1956），文中同时讨论了朴素估计量与一般核估计量。<sup>[12](https://doi.org/10.1214/aoms/1177728190)</sup> 伊曼纽尔·帕尔岑（Emanuel Parzen）的《论概率密度函数与众数的估计》（《数学统计年鉴》，1962）赋予 KDE 今日所用的形式，该方法也因此被称为 Parzen–Rosenblatt 窗方法。<sup>[13](https://doi.org/10.1214/aoms/1177704472)</sup><sup> • </sup><sup>[7](https://cswr.nrhstat.org/density)</sup> 此后又出现了若干后续构件：D. O. 洛夫茨加登（D. O. Loftsgaarden）与 C. P. 奎森伯里（C. P. Quesenberry）的最近邻估计量（《数学统计年鉴》，1965），<sup>[14](https://doi.org/10.1214/aoms/1177700079)</sup> 利奥·布雷曼（Leo Breiman）、威廉·迈泽尔（William Meisel）与爱德华·珀塞尔（Edward Purcell）的可变核方法（《技术计量学》，1977），<sup>[15](https://doi.org/10.1080/00401706.1977.10489521)</sup> 伊恩·S. 艾布拉姆森（Ian S. Abramson）的平方根律可变带宽（《统计年鉴》，1982），<sup>[16](https://doi.org/10.1214/aos/1176345986)</sup> 以及 伯纳德·W. 西尔弗曼（Bernard W. Silverman）的专著《统计与数据分析中的密度估计》（1986）——以他命名的经验法则即出自此书，该书于 1987 年在《技术计量学》上获得书评。<sup>[1](https://ned.ipac.caltech.edu/level5/March02/Silverman/paper.pdf)</sup><sup> • </sup><sup>[17](https://doi.org/10.2307/1269475)</sup>

## 变体

**自适应带宽。** M.C. 琼斯（M.C. Jones）（《澳大利亚统计杂志》，1990）区分了“可变核密度估计”的两种含义：为每个数据点使用不同带宽（样本点形式），以及带宽为估计位置的函数（气球形式）。<sup>[18](https://doi.org/10.1111/j.1467-842x.1990.tb01031.x)</sup> 艾布拉姆森的平方根律令每个样本点处的带宽与该点处先导密度估计的平方根成反比。<sup>[16](https://doi.org/10.1214/aos/1176345986)</sup><sup> • </sup><sup>[19](https://hal.science/hal-03775536v1/document)</sup>

**边界与条件方法。** 乔纳森·C. 马歇尔（Jonathan C. Marshall）与马丁·L. 黑泽尔顿（Martin L. Hazelton）（《多变量分析杂志》，2009）提出一种线性边界核，可降低自适应估计量的渐近边界偏差，并适用于不规则边界。<sup>[20](https://doi.org/10.1016/j.jmva.2009.09.003)</sup> B. U. 帕克（B. U. Park）及其合作者（《非参数统计杂志》，2003）引入了自适应可变位置估计量，在边界处将偏差改善一个数量级，同时改善内部的高阶偏差。<sup>[21](https://doi.org/10.1080/10485250306041)</sup> 扩散估计量提高了渐近精度，能自然处理定义域边界，使平滑程度自适应于数据，并且始终给出真正的密度。<sup>[22](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0259111)</sup>

**分数去偏 KDE。** SD-KDE 由埃利奥特·L. 爱泼斯坦（Elliot L. Epstein）及其同事于 2025 年报道：它沿估计的分数函数将每个数据点移动一步，再以修改后的带宽执行 KDE，使 AMISE 达到 \( O(n^{-8/(d+8)}) \) 阶，而非标准 KDE 的 \( O(n^{-4/(d+4)}) \) 阶。<sup>[5](https://papers.nips.cc/paper_files/paper/2025/file/fd8548947a14f68375d7e6235ab493ec-Paper-Conference.pdf)</sup><sup> • </sup><sup>[23](https://doi.org/10.48550/arxiv.2504.19084)</sup> 它使用由普通 KDE 经估计值对数梯度得到的经验分数，无需训练扩散模型，可视为朗之万动力学的一步 Euler–Maruyama 离散化；其理论保证假定存在精确的分数预言机，而这在实践中通常无法获得。<sup>[5](https://papers.nips.cc/paper_files/paper/2025/file/fd8548947a14f68375d7e6235ab493ec-Paper-Conference.pdf)</sup>

## 应用

所得估计可支持回归、分类、聚类、无监督预测与异常检测，以及从拟合密度中抽取新样本的非参数生成建模。<sup>[10](https://www.stat.cmu.edu/~larry/=sml/densityestimation.pdf)</sup><sup> • </sup><sup>[6](https://scikit-learn.org/stable/modules/density.html)</sup> 扩散模型可视为非参数密度估计的一种隐式方法：它不构造 \( p_0 \) 的直接估计量，而是借助估计的分数函数，通过基于分数的 MCMC 进行采样。<sup>[24](https://www.jmlr.org/papers/volume27/25-0121/25-0121.pdf)</sup><sup> • </sup><sup>[25](https://arxiv.org/pdf/2408.05807)</sup> 在可视化方面，迈克尔·C. 明诺特（Michael C. Minnotte）与大卫·W. 斯科特（David W. Scott）的众数树（《计算与图形统计杂志》，1993）概括了众数如何随带宽变化而出现并合并。<sup>[26](https://doi.org/10.1080/10618600.1993.10474599)</sup>

## 局限与替代方法

**失效模式。** 在样本空间边界附近，未经校正的 KDE 具有不趋于零的逐点偏差，通常为 \( O(1) \) 阶，且密度被低估；补救办法包括反射、变换、边界核与局部似然。<sup>[10](https://www.stat.cmu.edu/~larry/=sml/densityestimation.pdf)</sup><sup> • </sup><sup>[27](https://iis.uibk.ac.at/public/piater/courses/IIS/modules/KDE/KDE.notes.pdf)</sup> 对于长尾分布，固定带宽会在尾部产生虚假噪声，而平滑到足以消除这些噪声的程度，又会掩盖分布主体部分的重要细节，这正是自适应带宽的动因。<sup>[1](https://ned.ipac.caltech.edu/level5/March02/Silverman/paper.pdf)</sup>

**计算。** 对 \( n \) 个样本在 \( m \) 个点上进行朴素求值，需要 \( O(m \cdot n) \) 次核求值；当求值点与数据点重合时为 \( O(n^2) \)；且带宽选择目标在优化过程中必须反复求值。<sup>[28](https://ar5iv.labs.arxiv.org/html/1511.07482)</sup> 针对高斯核的基于 FFT 的计算，以及 fastKDE 方法——它将自洽 KDE 与基于 nuFFT 的计算相结合，且无需用户指定带宽——可将计算复杂度降至随样本数线性增长的量级，即 \( O(N \cdot q^D + M^D \log(M^D)) \)；存储每维 \( M \) 个点的 \( D \) 维网格需要 \( M^D \) 个数值。<sup>[29](https://escholarship.org/content/qt9g56181p/qt9g56181p.pdf?t=p7qvyp)</sup>

**替代方法。** 直方图对箱宽、箱起点与坐标方向敏感，且产生阶梯函数；KDE 则去掉了箱锚点，改为在每个数据点处放置一个块。<sup>[27](https://iis.uibk.ac.at/public/piater/courses/IIS/modules/KDE/KDE.notes.pdf)</sup><sup> • </sup><sup>[6](https://scikit-learn.org/stable/modules/density.html)</sup> 对小样本而言，有限混合模型在 EM 下会出现核塌缩，此时帕尔岑窗更受青睐；对大数据集而言，混合模型计算成本更低，而性能相当。<sup>[30](https://www.atlantis-press.com/article/1564.pdf)</sup>

**收敛性。** 罗森布拉特于 1956 年证明，任何非参数估计量都不可能无偏，任何误差度量也无法达到参数速率 \( O(n^{-1}) \)。<sup>[31](https://www.stat.rice.edu/~scottdw/ss.nh.pdf)</sup> 估计密度所需的样本数随维数呈指数增长，即维数灾难；在流形假设下，收敛速率取决于流形维数 \( d_M \) 而非环境维数，从而缓解了这一问题。<sup>[32](https://proceedings.mlr.press/v70/jiang17b/jiang17b.pdf)</sup>

## References

1. [Density Estimation for Statistics and Data Analysis (B.W. Silverman, 1986; online edition)](https://ned.ipac.caltech.edu/level5/March02/Silverman/paper.pdf)
2. [Density Estimation Based on Kernel Methods (Sheather, Statistical Science 2004)](https://eliassi.org/Sheather_StatSci_2004.pdf)
3. [Minimax density estimation for growing dimension (McDonald et al., ICML 2017)](https://proceedings.mlr.press/v54/mcdonald17a/mcdonald17a.pdf)
4. [Bandwidth selection | A Short Course on Nonparametric Curve Estimation](https://egarpor.github.io/NP-EAFIT/dens-bwd.html)
5. [SD-KDE: Score-Debiased Kernel Density Estimation (NeurIPS 2025)](https://papers.nips.cc/paper_files/paper/2025/file/fd8548947a14f68375d7e6235ab493ec-Paper-Conference.pdf)
6. [2.8. Density Estimation, scikit-learn documentation](https://scikit-learn.org/stable/modules/density.html)
7. [Chapter 2 Density estimation | Computational Statistics with R](https://cswr.nrhstat.org/density)
8. [A Course in Density Estimation (L. Devroye, 1987)](https://luc.devroye.org/Devroye-ACourseInDensityEstimation-1987.pdf)
9. [A Reliable Data-Based Bandwidth Selection Method for Kernel Density Estimation (Sheather & Jones, JRSS-B, 1991)](https://rss.onlinelibrary.wiley.com/doi/10.1111/j.2517-6161.1991.tb01857.x)
10. [Density Estimation (Wasserman, lecture notes, CMU 10-725)](https://www.stat.cmu.edu/~larry/=sml/densityestimation.pdf)
11. [Density Estimation course notes (SYS6018)](https://mdporter.github.io/SYS6018/lectures/density.pdf)
12. [Murray Rosenblatt (1956). Remarks on Some Nonparametric Estimates of a Density Function. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177728190)
13. [Emanuel Parzen (1962). On Estimation of a Probability Density Function and Mode. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177704472)
14. [D. O. Loftsgaarden, C. P. Quesenberry (1965). A Nonparametric Estimate of a Multivariate Density Function. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177700079)
15. [Leo Breiman, William Meisel, Edward Purcell (1977). Variable Kernel Estimates of Multivariate Densities. Technometrics.](https://doi.org/10.1080/00401706.1977.10489521)
16. [Ian S. Abramson (1982). On Bandwidth Variation in Kernel Estimates-A Square Root Law. The Annals of Statistics.](https://doi.org/10.1214/aos/1176345986)
17. [Khosrow Dehnad, Bernard Silverman (1987). Density Estimation for Statistics and Data Analysis. Technometrics.](https://doi.org/10.2307/1269475)
18. [M.C. Jones (1990). VARIABLE KERNEL DENSITY ESTIMATES AND VARIABLE KERNEL DENSITY ESTIMATES. Australian Journal of Statistics.](https://doi.org/10.1111/j.1467-842x.1990.tb01031.x)
19. [Optimal bandwidth selection for variable kernel density estimation](https://hal.science/hal-03775536v1/document)
20. [Jonathan C. Marshall, Martin L. Hazelton (2009). Boundary kernels for adaptive density estimators on regions with irregular boundaries. Journal of Multivariate Analysis.](https://doi.org/10.1016/j.jmva.2009.09.003)
21. [B. U. Park and colleagues (2003). Adaptive variable location kernel density estimators with good performance at boundaries. Journal of nonparametric statistics.](https://doi.org/10.1080/10485250306041)
22. [Semiparametric maximum likelihood probability density estimation (PLOS One)](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0259111)
23. [Epstein, Elliot L. and colleagues (2025). SD-KDE: Score-Debiased Kernel Density Estimation. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2504.19084)
24. [Nonparametric Estimation of a Factorizable Density using Diffusion Models (JMLR, vol. 27)](https://www.jmlr.org/papers/volume27/25-0121/25-0121.pdf)
25. [Kernel density estimation in high dimension: three statistical regimes (glassy phases) (arXiv, 2024)](https://arxiv.org/pdf/2408.05807)
26. [Michael C. Minnotte, David W. Scott (1993). The Mode Tree: A Tool for Visualization of Nonparametric Density Features. Journal of Computational and Graphical Statistics.](https://doi.org/10.1080/10618600.1993.10474599)
27. [Kernel Density Estimation - An Introduction (Piater, Universität Innsbruck)](https://iis.uibk.ac.at/public/piater/courses/IIS/modules/KDE/KDE.notes.pdf)
28. [FFT-Based Fast Bandwidth Selector for Multivariate Kernel Density Estimation (arXiv 1511.07482)](https://ar5iv.labs.arxiv.org/html/1511.07482)
29. [A fast and objective multidimensional kernel density estimation method: fastKDE (O'Brien et al., Computational Statistics and Data Analysis, 2016)](https://escholarship.org/content/qt9g56181p/qt9g56181p.pdf?t=p7qvyp)
30. [A comparative study of various probability density estimation methods for data analysis](https://www.atlantis-press.com/article/1564.pdf)
31. [Multi-dimensional Density Estimation (D. Scott, textbook chapter)](https://www.stat.rice.edu/~scottdw/ss.nh.pdf)
32. [Uniform Convergence Rates for Kernel Density Estimation (Jiang, ICML 2017)](https://proceedings.mlr.press/v70/jiang17b/jiang17b.pdf)

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

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Estimation theory and estimator families

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/density-estimation

English original: https://www.edgepedia.org/density-estimation
