用概率数据拟合python中的伽马分布

时间:2020-05-06 05:55:59

标签: python gamma-distribution

我有两个数据:

x_data = 
[   0.0,   50.0,  100.0,  150.0,  200.0,  250.0,  300.0,  350.0,  400.0,
  450.0,  500.0,  550.0,  600.0,  650.0,  700.0,  750.0,  800.0,  850.0,
  900.0,  950.0, 1000.0, 1100.0, 1200.0, 1500.0, 2000.0]

    y_data = 
[0.005758157389635317, 0.061420345489443376,  0.06525911708253357,
  0.07677543186180423,   0.0690978886756238,   0.0690978886756238,
  0.05374280230326296, 0.055662188099808066,  0.05182341650671785,
  0.04414587332053743, 0.038387715930902115, 0.057581573896353176,
 0.057581573896353176,  0.04030710172744722,  0.02687140115163148,
 0.024952015355086368, 0.030710172744721688,  0.02111324376199616,
  0.02111324376199616, 0.015355086372360844, 0.030710172744721688,
 0.019193857965451054, 0.038387715930902115,  0.01343570057581574,
 0.011516314779270634]

那里的数据意味着x在0到50之间的概率是0.005758157389635317,x在50到100之间的概率是0.061420345489443376,依此类推。

我想将此数据拟合为伽马分布。我的代码是:

shape2, loc2, scale2 = gamma.fit(y_data)
g2 = gamma.pdf(x=x_data, a=shape2, loc=loc2, scale=scale2)


plt.scatter(x_data,y_data)
plt.plot(x_data, g2, 'r-', linewidth=1, alpha=.6)
plt.annotate(s='shape = %.3f\nloc = %.3f\nscale = %.3f' % (shape2, loc2, scale2), xy=(6, .2))

plt.show()

结果似乎不是我想要的。 enter image description here

如何拟合这些数据?谢谢!

0 个答案:

没有答案