python - 使用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正确地制作高斯核密度函数?
解决方案
推荐阅读
- javascript - 如何在 javascript 文件中使用 JSON.stringify() 从 node.js 中检索对象?
- swift - 限制swift中的字符数
- r - 预订文档的可用输出键值选项?
- ansible - 如何使用 Ansible ipaddr 获取子网中的 IP 范围
- python - 如何评估模板中 2 个变量的串联?
- facebook - 是否可以在单个查询中查询媒体洞察?
- google-cloud-platform - 如何创建 Google Container Registry 永久令牌?
- reactjs - 有没有办法用从后端收到的数据更新表
- artifactory - 有没有办法在 Artifactory 构建信息中引用依赖项而不在本地下载依赖项?
- powershell - 为什么 powershell 抱怨注释行?