Fitting a gamma distribution with (python) Scipy

后端 未结 5 1712
情歌与酒
情歌与酒 2020-12-09 02:24

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 dis

5条回答
  •  不知归路
    2020-12-09 03:02

    Generate some gamma data:

    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)
    

提交回复
热议问题