首页 > 解决方案 > 使用skipy的高斯核估计

问题描述

我正在尝试使用skipy创建一个核密度函数。下面是我的代码:

# Gaussian Kernel Estimate
gaussian_data = np.random.normal(loc=np.mean(perthR), scale=np.std(perthR), size=2000).reshape(-1,1)
loc = np.linspace(min(i),max(i),100) #create 100 equally spaced points across the data range
kdepdf=scstats.gaussian_kde(gaussian_data).evaluate(loc) #initiate and get the kernel density estimate 

#plot estimated density
plt.plot(loc, kdepdf, lw= 2, label='Kernel Density Function', c = 'c')

其中 perthR 表示 2015 年全年珀斯的每日降雨量,大小为 80 的数组。

但是,我不断收到以下错误:

ValueError: array must not contain infs or NaNs

即使我一遍又一遍地检查并且数据集没有低于 0.25 或高于 40 的值并且没有 NaNs

任何人都知道如何用skipy正确地制作高斯核密度函数?

标签: pythonkernel-density

解决方案


推荐阅读