Python Scipy 核密度估计平滑问题

Python Scipy Kernel Density Estimate Smoothing Issues

很抱歉提出一个答案可能非常明显的问题,但我对如何调整 KDE 的平滑程度感到有点困惑。我的代码在 python:

中看起来像这样
kde = scipy.stats.gaussian_kde(c)
P_0 = kde(3)
P_c = kde(c)

其中 c 只是一列数字,我想对上面的内容进行积分(这对于我遇到的问题来说不太重要)。我对如何更改 scipy 中的 scott/silverman 方法以允许 over/undersmoothing.

有点困惑

您似乎想调整 set_bandwidth 参数。 link 包含简单的示例代码,我在这里将其简化为最基本的元素:

kde = stats.gaussian_kde(c)
kde.set_bandwidth(bw_method=.3)
P = kde(c)

基本上,带宽是通过 kde.set_bandwidth(bw_method=X) 调用设置的,其中 X 通常是浮点数或方法 silvermanscott 之一。完整的描述实际上指出 bw_method:

can be ‘scott’, ‘silverman’, a scalar constant or a callable. If a scalar, this will be used directly as kde.factor. If a callable, it should take a gaussian_kde instance as only parameter and return a scalar.