3
我需要适合泊松分布到一组数据:泊松分布适合
fitfunc = lambda p, x: p[0]*pow(p[1],x)*pow(e,-p[1])/math.gamma(x+1) # Target function
errfunc = lambda p, x, y: fitfunc(p, x) - y # Distance to the target function
p0 = [1., 2.] # Initial guess for the parameters
p1, success = optimize.leastsq(errfunc, p0[:], args=(bins_mean, n))
我提出,使用在SciPy documentation给出的例子。
如果我对伽玛函数部分发表评论,它就像一个魅力,所以问题在那里,但我不知道如何解决它。
我得到以下错误:
TypeError: can only concatenate list (not "int") to list
拟合的输入参数是plt.hist的输出,我检查和类型是numpy的ndarray
你会得到什么错误? –
如果你有数据(不只是直方图),这里没有必要进行优化。对于泊松分布,只需通过“np.mean(data)”就可以分析找到最合适的参数(lambda,你的'p [1]')。 'p [0]'只是标准化。 – askewchan
是'bins_mean'和'n' numpy数组吗?错误使我相信你正在通过列表。 –