使用(python)Scipy拟合伽马分布 [英] Fitting a gamma distribution with (python) Scipy

查看:72
本文介绍了使用(python)Scipy拟合伽马分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我在 python 中拟合伽马分布?好吧,我有一些数据:X 和 Y 坐标,我想找到适合这个分布的伽玛参数......在 Scipy doc,事实证明fit方法确实存在,但我不知道如何使用它:s.. 首先,参数数据"必须采用哪种格式,以及如何提供第二个参数(参数),因为这是我正在寻找的内容?

Can anyone help me out in fitting a gamma distribution in python? Well, I've got some data : X and Y coordinates, and I want to find the gamma parameters that fit this distribution... In the Scipy doc, it turns out that a fit method actually exists but I don't know how to use it :s.. First, in which format the argument "data" must be, and how can I provide the second argument (the parameters) since that's what I'm looking for?

推荐答案

生成一些伽马数据:

import scipy.stats as stats    
alpha = 5
loc = 100.5
beta = 22
data = stats.gamma.rvs(alpha, loc=loc, scale=beta, size=10000)    
print(data)
# [ 202.36035683  297.23906376  249.53831795 ...,  271.85204096  180.75026301
#   364.60240242]

这里我们将数据拟合到伽马分布:

Here we fit the data to the gamma distribution:

fit_alpha, fit_loc, fit_beta=stats.gamma.fit(data)
print(fit_alpha, fit_loc, fit_beta)
# (5.0833692504230008, 100.08697963283467, 21.739518937816108)

print(alpha, loc, beta)
# (5, 100.5, 22)

这篇关于使用(python)Scipy拟合伽马分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆