python - `scipy.stats.binned_statistic` 分箱值的标准差

标签 python statistics binning

当我根据 scipy.stats.binned_statistic ( see here for example ) 对数据进行分箱时,如何获得平均分箱值的误差(即标准差)?

例如,如果我按如下方式对数据进行分类:

windspeed = 8 * np.random.rand(500)
boatspeed = .3 * windspeed**.5 + .2 * np.random.rand(500)
bin_means, bin_edges, binnumber = stats.binned_statistic(windspeed,
             boatspeed, statistic='median', bins=[1,2,3,4,5,6,7])
plt.figure()
plt.plot(windspeed, boatspeed, 'b.', label='raw data')
plt.hlines(bin_means, bin_edges[:-1], bin_edges[1:], colors='g', lw=5,
        label='binned statistic of data')
plt.legend()

如何获得bin_means的标准差?

最佳答案

解决这个问题的方法是根据直方图构建概率密度估计(这只是适当标准化直方图的问题),然后计算估计密度的标准差或任何其他统计量。

适当的归一化是使直方图下的面积达到 1 所需的任何值。至于计算密度估计的统计量,请根据统计量的定义进行计算:integral(p(x)*f( x), x, -无穷大, +无穷大),替换 p(x) 的密度估计以及 f(x) 所需的任何内容,例如xx^2 获取第一和第二时刻,从中计算方差,然后计算标准差。

我明天会发布一些公式,或者也许其他人想同时尝试一下。您也许可以查找一些公式,但我的建议是在查找答案之前始终尝试找出答案。

关于python - `scipy.stats.binned_statistic` 分箱值的标准差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48997277/

相关文章:

python - 生成以 y 轴作为相对频率的直方图?

neural-network - 如何从深度 CNN 输出创建不确定性彩色 map 图像?

python连续出现的长度

r - 如何在 R 中绘制预分箱直方图

python - 在 Python 中分箱后返回范围的下限或上限

python - 为 python 2.7 安装 scipy

python - Django:如何 'scrub' 用户列表

python - Pandas 根据列 dtypes 进行应用

python - 检查一个数字是否是一个完美的正方形

python - 相互引用的两个数据集的直方图分箱