Python-Scipy核密度估计平滑问题

2024-04-26 02:24:04 发布

您现在位置:Python中文网/ 问答频道 /正文

很抱歉问一个可能有一个非常明显的答案的问题,但我有点困惑,如何调整我可以与KDE平滑。我的代码在python中如下所示:

kde = scipy.stats.gaussian_kde(c)
P_0 = kde(3)
P_c = kde(c)

其中c只是一列数字,我想对上面的数字做一个积分(这对我的问题来说并不太重要)。我有点困惑,我将如何更改scipy中的scott/silverman方法,以允许一些过度/不足平滑。在


Tags: 方法答案代码stats数字scipygaussianscott
1条回答
网友
1楼 · 发布于 2024-04-26 02:24:04

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

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

所以基本上,带宽是通过kde.set_bandwidth(bw_method=X)调用来设置的,其中X通常是一个浮点或{},scott方法之一。完整的描述实际上表明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.

相关问题 更多 >