views:

290

answers:

1

Hi folks,

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 wich format the argument "data" must be, and how can I provide the seconde argument (the parameters) since this what I'm looking for ???

Thanks a lot!

+1  A: 
import scipy.stats as ss
import scipy as sp

Generate some gamma data:

alpha=5
loc=100.5
beta=22
data=ss.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=ss.gamma.fit(data)
print(fit_alpha,fit_loc,fit_beta)
# (5.0833692504230008, 100.08697963283467, 21.739518937816108)

print(alpha,loc,beta)
# (5, 100.5, 22)
unutbu
Thanks a lot ! But why did you create the variable x in the beginning ?
Archanimus
Ah, it seems that my message is too late.Thanks you very much again ;)
Archanimus