简体   繁体   English

scipy.stats:高斯带宽因子 kernel 密度估计器

[英]scipy.stats : bandwidth factor in gaussian kernel density estimator

I generated a 2D gaussian distribution (uncorrelated datas)我生成了一个二维高斯分布(不相关的数据)

dist2=np.array([np.random.normal(loc=10,scale=3, size=50000),np.random.normal(loc=5,scale=2, size=50000)])

I calculated the covariance matrix divided by bandwidth factor because the covariance attribute is The covariance matrix of dataset, scaled by the calculated bandwidth (kde.factor) ( https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.gaussian_kde.html )我计算了协方差矩阵除以带宽因子,因为协方差属性是数据集的协方差矩阵,由计算的带宽(kde.factor)缩放https://docs.scipy.org/doc/scipy/reference/generated/scipy .stats.gaussian_kde.html

from scipy.stats import kde
# Use a kernel density estimator to produce local-counts in this space, and grid them to plot.
k = kde.gaussian_kde(dist2)
k.covariance/k.factor

Diagonal elements are not the square of the sigmas as expected.对角元素不是预期的 sigma 的平方。

I think there is something I have not understood on this bandwidth factor.我认为在这个带宽因素上有一些我不明白的东西。

Any explanation would be appreciated.任何解释将不胜感激。 Thanks for help.感谢帮助。

In scipy.stats.kde.gaussian_kde the covariance factor is implemented so that k.covariance / k.factor**2 is ~ to np.cov(dist2) .scipy.stats.kde.gaussian_kde中,实现了协方差因子,因此k.covariance / k.factor**2是 ~ 到np.cov(dist2)

Se here for details Getting bandwidth used by SciPy's gaussian_kde function Se here for details 获取 SciPy 的 gaussian_kde function 使用的带宽

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM