用正态分布拟合加权直方图 [英] Fitting a weighted histogram with a normal distribution
问题描述
我知道如何使用SCipy库拟合以正态分布输入直方图的数据(用python拟合直方图),但是如果在具有数据的基础上又具有相同维度的权重数组,我该怎么做?有适当的功能吗?还是我应该创建一个由数据提供数据并对其加权的第二个数组?
I know how to fit the data entering an histogram with a normal distribution using the SCipy library (Fitting a histogram with python) but how could I do the same if on top of having data I have an array of weights having the same dimension. Is there a proper function for that or should I create a second array fed by the data and weighting it myself?
干杯.
这已经在这里得到了答案:
This is pretty much already answered here:
推荐答案
如果您正在寻找正态分布N(mu,sigma) 您可以从输入数据中精确计算出mu和sigma.
If you are looking for a Normal distribution N(mu, sigma) you can calculate exactly mu and sigma from the input data.
例如:X = x1,...,xN是值,W = w1,...,wN是权重
For example: X = x1,...,xN are the values and W = w1,..., wN their weights
mu = sum (X * W) / sum(W)
sigma = np.sqrt (sum (W * (X- mu)**2) / sum(W))
If you are to fit another kind of distribution, I suggested an answer here using OpenTURNS library.
这篇关于用正态分布拟合加权直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!