# 核密度估计

**核密度估计**（Kernel density estimation，KDE）是一种非参数统计方法，用于从数据中估计分布的概率密度函数，其做法是在每个观测数据点周围放置一个平滑的加权函数（核），再将各点的贡献加总。该方法不对密度作任何参数形式的假设，所得曲线的平滑程度由单一调节参数——带宽——控制。<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup><sup> • </sup><sup>[2](https://www.cambridge.org/core/books/modern-statistical-methods-and-theory/kernel-density-estimation/DB1D9E5D59B46FBEE1893823CAAAF0EA)</sup>

| 关键事实 | 详情 |
|---|---|
| 估计量 | \( \hat{f}_n(x) = \frac{1}{nh} \sum_{j=1}^{n} K\!\left(\frac{x - X_j}{h}\right) \)，其中 \( K \) 为核函数，\( h \) 为平滑参数（带宽）<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup> |
| 起源 | 由默里·罗森布拉特（Murray Rosenblatt）引入，见《关于密度函数某些非参数估计的评注》，《数学统计年鉴》27(3): 832–837（1956）<sup>[3](https://www.minicod.com/papers/remarks-on-some-nonparametric-estimates-of-a-density-function-2f304cb0)</sup> |
| 推广 | 伊曼纽尔·帕尔岑（Emanuel Parzen），《论概率密度函数与众数的估计》，《数学统计年鉴》33: 1065–1076（1962）<sup>[4](https://www.sciencedirect.com/topics/mathematics/kernel-estimate)</sup> |
| 西尔弗曼经验法则 | 默认带宽 \( 0.9 \cdot \min(s, \mathrm{IQ}/1.34) \cdot n^{-1/5} \)，其中 \( s \) 为样本标准差，IQ 为四分位距；若数据确实服从正态分布，最优宽度为 \( 1.06 \cdot s \cdot n^{-1/5} \)<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup> |
| 敏感性 | 就均方误差而言，估计量对带宽的敏感程度高于对核函数选择的敏感程度<sup>[5](https://hydrology.usu.edu/dtarb/Rajagopalan_Lall_Tarboton_Bowles_1997.pdf)</sup> |
| 收敛速率 | \( O(n^{-4/(d+4)}) \) 的速率随维数 \( d \) 增大而变慢，即维数灾难，此术语由贝尔曼（Bellman，1961）提出<sup>[6](https://www.researchgate.net/publication/345554382_Density_estimation)</sup> |
| 实际用途 | 探索性数据分析中的密度曲线、空间点数据的热力图，以及随机结构的经济计量建模<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC9187053/)</sup><sup> • </sup><sup>[8](https://dergipark.org.tr/en/pub/ier/article/278024)</sup>  |

## 定义与机制

给定来自密度 \( f \) 的 \( n \) 个观测 \( X_1, \dots, X_n \)，在点 \( x \) 处的核密度估计为<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup>

\[ \hat{f}_n(x) = \frac{1}{nh} \sum_{j=1}^{n} K\!\left(\frac{x - X_j}{h}\right) \]

其中 \( K \) 为核函数，通常是高斯核、叶帕涅奇尼科夫核、矩形核、三角核或双权核等对称概率密度，\( h \) 为带宽，也称平滑参数或窗口宽度。估计量在 \( x \) 处的取值，就是该点处 \( n \) 个核纵坐标的平均值。<sup>[9](https://www.math.canterbury.ac.nz/~c.scarrott/evmix/thesis.pdf)</sup>

核函数不必是密度函数，估计量照样成立。一个经典结果——定理 A（博赫纳定理）——只要求核函数有界、绝对可积且在无穷远处趋于零；它保证在真实密度的每个连续点上，估计值收敛到 \( f(x) \) 乘以核函数的积分，而对密度核而言该积分为 1。<sup>[4](https://www.sciencedirect.com/topics/mathematics/kernel-estimate)</sup>

## 历史

概率密度函数核估计的概念由统计学家默里·罗森布拉特提出，他 1956 年发表于《数学统计年鉴》的论文分析了一元密度的估计。该文证明，凡满足相对温和条件的密度估计都是有偏的，并评估了某一特定类别估计的渐近均方误差。<sup>[3](https://www.minicod.com/papers/remarks-on-some-nonparametric-estimates-of-a-density-function-2f304cb0)</sup> 这一方法经 E. 帕尔岑 1962 年的一篇奠基性论文而广为流传，该文包含了估计量渐近性质的证明。<sup>[4](https://www.sciencedirect.com/topics/mathematics/kernel-estimate)</sup> 此后的里程碑包括逐点相合性、固定带宽下的几乎必然一致收敛，以及固定带宽与可变带宽的收敛速率。<sup>[10](https://www.researchgate.net/publication/302566511_Consistency_of_the_kernel_density_estimator_-_a_survey)</sup>

## 带宽选择

带宽是对输出影响最大的单一参数，其影响超过核函数的选择。带宽小，估计量对每个数据点反应敏锐，能捕捉真实结构，但也会拾取噪声；带宽大则过度平滑，原本分明的簇可能模糊成一条曲线，重尾分布也可能看起来是对称的。<sup>[11](https://www.datacamp.com/tutorial/kernel-density-estimation)</sup> 西尔弗曼指出，就均方误差而言，估计量对带宽的敏感程度高于对核函数的敏感程度，因此通常的做法是先固定核函数，再在某种准则下寻求最优带宽。<sup>[5](https://hydrology.usu.edu/dtarb/Rajagopalan_Lall_Tarboton_Bowles_1997.pdf)</sup>

**经验法则。** 西尔弗曼经验法则根据样本量和数据的离散程度选取带宽。DATAPLOT 的参考实现使用 \( 0.9 \cdot \min(s, \mathrm{IQ}/1.34) \cdot n^{-1/5} \)，其中将四分位距除以 1.34 可得到正态数据标准差的相合估计；若数据事实上服从正态分布，最优宽度为 \( 1.06 \cdot s \cdot n^{-1/5} \)。<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup> 该法则对近似正态的分布效果良好，但对多峰分布可能过度平滑。<sup>[11](https://www.datacamp.com/tutorial/kernel-density-estimation)</sup>

**数据驱动的选择器。** 自动方法分为两类：一类是经典方法，如交叉验证、马洛 \( C_p \) 和 AIC，它们扩展了参数模型选择的思路；另一类是插入法，先对未知密度作一个初步估计，再将其代入平均积分平方误差（MISE）的估计式中。<sup>[12](https://www.researchgate.net/publication/233885934_A_Review_of_Kernel_Density_Estimation_with_Applications_to_Econometrics)</sup> 希瑟与琼斯（Sheather and Jones，1991）的插入法根据 MISE 的一阶近似选取带宽，往往表现优异，但它需要预先估计依赖于未知真实密度的量，且向多元密度的推广不那么直接。<sup>[13](https://www.sciencedirect.com/science/article/pii/S0165176520301105)</sup> 由鲁德莫（Rudemo，1982）和鲍曼（Bowman，1984）提出的最小二乘交叉验证直接估计 MISE，概念上简单明了。<sup>[13](https://www.sciencedirect.com/science/article/pii/S0165176520301105)</sup> 似然交叉验证由哈贝马、赫尔曼斯和范登布鲁克以及杜因提出，它最大化留一法对数似然，并最小化估计密度与真实密度之间的库尔贝克-莱布勒距离。<sup>[12](https://www.researchgate.net/publication/233885934_A_Review_of_Kernel_Density_Estimation_with_Applications_to_Econometrics)</sup>

交叉验证带宽受样本波动影响大，常常选出过小的带宽，产生欠平滑、带有虚假起伏的估计。<sup>[14](https://www3.stat.sinica.edu.tw/statistica/j6n1/j6n18/j6n18.htm)</sup><sup> • </sup><sup>[12](https://www.researchgate.net/publication/233885934_A_Review_of_Kernel_Density_Estimation_with_Applications_to_Econometrics)</sup> 邱（Chiu）的一篇综述指出，在基于特征函数的选择器中，各种程序之间的主要差别在于用来估计平均积分平方误差的第二个带宽的选择，而这一选择极大地影响性能。<sup>[14](https://www3.stat.sinica.edu.tw/statistica/j6n1/j6n18/j6n18.htm)</sup> 尚无任何一种带宽选择程序在任何情形下都被认为是最优的。<sup>[12](https://www.researchgate.net/publication/233885934_A_Review_of_Kernel_Density_Estimation_with_Applications_to_Econometrics)</sup>

## 精度与局限

估计量的误差可分解为偏差的平方与方差。在渐近平均积分平方误差（AMISE）中，渐近积分方差与渐近积分平方偏差之比为 4:1，因此在最优点处方差的贡献是偏差的四倍。<sup>[15](https://onlinelibrary.wiley.com/doi/10.1002/9781118575574.ch6)</sup> 小带宽降低偏差但增大方差，大带宽则相反。<sup>[16](https://www.mvstat.net/mvksa/mvksa.pdf)</sup>

**边界偏差。** 所有核方法共有的一个问题是边界偏差：在密度支撑集端点附近的点上，表现与内部点不同，因为边界之外的数据无法对称地作出贡献。自适应方法先计算一个初步估计，再用它来在数据各处改变带宽。<sup>[17](https://pmc.ncbi.nlm.nih.gov/articles/PMC5978534/)</sup> 有大量文献处理边界偏差校正，主要集中在一元情形，而多元边界核可以通过若干成熟技术构造。<sup>[18](https://doi.org/10.1016/j.jmva.2009.09.003)</sup>

**维数。** 多元核密度估计受维数灾难之苦：每增加一个随机变量都会增加难度，而对每个 \( d \)，收敛速率 \( O(n^{-4/(d+4)}) \) 都一致地慢于参数速率 \( O(n^{-1}) \)，这使得非参数核估计成为比其参数对应物更难的问题。<sup>[6](https://www.researchgate.net/publication/345554382_Density_estimation)</sup><sup> • </sup><sup>[16](https://www.mvstat.net/mvksa/mvksa.pdf)</sup> 近期的理论工作已将一致收敛界推广到集中于低维流形上的分布，表明该速率可以适应数据的内在体积维数。<sup>[19](https://proceedings.mlr.press/v97/kim19e/kim19e.pdf)</sup>

## 计算与软件

西尔弗曼（1982）展示了如何用快速傅里叶变换计算核密度估计，这如今已成为统计软件中的标准做法。<sup>[1](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)</sup> R 的 `density()` 函数将经验分布函数的质量分散到至少 512 个点的规则网格上，用 FFT 将其与离散化的核函数卷积，再做线性插值；其核函数经过缩放，使带宽等于核函数的标准差，而默认带宽规则 `"nrd0"` 是出于历史与兼容性原因保留的，并非作为一般性推荐。<sup>[20](https://www.stat.ethz.ch/R-manual/R-devel/library/stats/html/density.html)</sup> scikit-learn 的 `KernelDensity` 类提供高斯核、顶帽核、叶帕涅奇尼科夫核、指数核、线性核和余弦核，并配有斯科特与西尔弗曼带宽规则以及用于快速求值的基于树的算法。<sup>[21](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KernelDensity.html)</sup>

## 应用

凡是在没有参数模型的情况下需要对分布作连续观察之处，都会用到核密度估计。与直方图相比，它避免了离散化边界带来的不稳定性，可以非正式地理解为对所有直方图选择所作的连续平均；在不同数据集之间也比较容易比较。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC9187053/)</sup><sup> • </sup><sup>[22](https://haralick.org/DV/Handbook_of_Data_Visualization.pdf)</sup> 在空间分析中，KDE 是热力图背后的统计前提，把点数据转化为连续曲面；对空间数据而言，经验法则带宽往往会使成簇的、有界的数据过度平滑，因此只能作为起点而非最终答案。<sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC9187053/)</sup><sup> • </sup><sup>[23](https://spatialworkflow.io/kernel-density-explained/)</sup> 在经济计量学中，非参数密度估计被用来为数据的概率结构建模，肖杜里与马龙（Chaudhuri and Marron，2000）的 SiZer 方法则分析密度估计中哪些可见特征在不同带宽下代表真实的底层结构。<sup>[8](https://dergipark.org.tr/en/pub/ier/article/278024)</sup> 其他应用包括众数回归、密度水平集与最高密度区域估计，以及复杂模型的近似似然推断。<sup>[24](https://arxiv.org/abs/1710.07004)</sup><sup> • </sup><sup>[25](https://arxiv.org/abs/1806.00731)</sup><sup> • </sup><sup>[26](https://www.sciencedirect.com/science/article/abs/pii/S0167947316301050)</sup>

## References

1. [Kernel Density Width, DATAPLOT Reference Manual, National Institute of Standards and Technology](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/kernwidt.htm)
2. [Kernel density estimation, in *Modern Statistical Methods and Theory* (Cambridge University Press)](https://www.cambridge.org/core/books/modern-statistical-methods-and-theory/kernel-density-estimation/DB1D9E5D59B46FBEE1893823CAAAF0EA)
3. [Murray Rosenblatt (1956). Remarks on Some Nonparametric Estimates of a Density Function. *The Annals of Mathematical Statistics* 27(3): 832–837.](https://www.minicod.com/papers/remarks-on-some-nonparametric-estimates-of-a-density-function-2f304cb0)
4. [Kernel Estimate – an overview, ScienceDirect Topics](https://www.sciencedirect.com/topics/mathematics/kernel-estimate)
5. [Rajagopalan, Lall, Tarboton and Bowles (1997), section 2.3, Kernel density estimation](https://hydrology.usu.edu/dtarb/Rajagopalan_Lall_Tarboton_Bowles_1997.pdf)
6. [Density estimation (ResearchGate preprint)](https://www.researchgate.net/publication/345554382_Density_estimation)
7. [Visualization of Big Spatial Data using Coresets for Kernel Density Estimates, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC9187053/)
8. [Zambom, A. Z. and Dias, R. (2013). A Review of Kernel Density Estimation with Applications to Econometrics. *International Econometric Review* 5(1): 20–42.](https://dergipark.org.tr/en/pub/ier/article/278024)
9. [Scarrott, C. (2012), section 2.4, Kernel Density Estimation (thesis)](https://www.math.canterbury.ac.nz/~c.scarrott/evmix/thesis.pdf)
10. [Consistency of the kernel density estimator – a survey (ResearchGate)](https://www.researchgate.net/publication/302566511_Consistency_of_the_kernel_density_estimator_-_a_survey)
11. [Kernel Density Estimation: From Theory to Practice, DataCamp](https://www.datacamp.com/tutorial/kernel-density-estimation)
12. [A Review of Kernel Density Estimation with Applications to Econometrics (full text, ResearchGate)](https://www.researchgate.net/publication/233885934_A_Review_of_Kernel_Density_Estimation_with_Applications_to_Econometrics)
13. [Robust kernels for kernel density estimation, Statistics & Probability Letters (ScienceDirect)](https://www.sciencedirect.com/science/article/pii/S0165176520301105)
14. [Chiu, S.-T. (1996). A comparative review of bandwidth selection for kernel density estimation. *Statistica Sinica* 6(1).](https://www3.stat.sinica.edu.tw/statistica/j6n1/j6n18/j6n18.htm)
15. [Kernel Density Estimators, Wiley Series in Probability and Statistics, Chapter 6](https://onlinelibrary.wiley.com/doi/10.1002/9781118575574.ch6)
16. [Multivariate Kernel Smoothing and Its Applications](https://www.mvstat.net/mvksa/mvksa.pdf)
17. [Examining Potential Boundary Bias Effects in Kernel Smoothing on Equating, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC5978534/)
18. [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)
19. [Uniform Convergence Rate of the Kernel Density Estimator Adaptive to Intrinsic Volume Dimension, PMLR v97](https://proceedings.mlr.press/v97/kim19e/kim19e.pdf)
20. [R: Kernel Density Estimation, stats::density documentation](https://www.stat.ethz.ch/R-manual/R-devel/library/stats/html/density.html)
21. [sklearn.neighbors.KernelDensity, scikit-learn documentation](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KernelDensity.html)
22. [Multivariate Visualization by Density Estimation, in *Handbook of Data Visualization*](https://haralick.org/DV/Handbook_of_Data_Visualization.pdf)
23. [Kernel Density Explained: What a Heatmap Actually Shows, Spatial Workflow](https://spatialworkflow.io/kernel-density-explained/)
24. [Modal Regression using Kernel Density Estimation: a Review, arXiv](https://arxiv.org/abs/1710.07004)
25. [Bandwidth selection for kernel log-density estimation and highest density regions, arXiv](https://arxiv.org/abs/1806.00731)
26. [Bandwidth selection for kernel log-density estimation, Statistics and Computing (ScienceDirect)](https://www.sciencedirect.com/science/article/abs/pii/S0167947316301050)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

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

Copyright 2026 Edgepedia

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

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

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