使用python scipy使伽玛分布适合数据 [英] Using python scipy to fit gamma distribution to data

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

问题描述

我想使用我的数据拟合伽玛分布

I want to fit a gamma distribution to my data, which I do using this

import scipy.stats as ss
import scipy as sp
import numpy as np
import os
import matplotlib.pyplot as plt

alpha = []
beta = []
loc = []

data = np.loadtxt(data)
fit_alpha, fit_loc, fit_beta = ss.gamma.fit(data, floc=0, fscale=1)

我想将参数之一保留在gamma分布中作为变量(例如形状),并固定其中一个参数(例如scale=1).但是,如果将loc变量保持为零,则无法将小数位固定为1.有一些解决方法吗?我不能仅使用形状和比例参数化伽玛分布吗?

I want to keep one of the parameters to the gamma distribution as a variable (say the shape), and fix one of the parameters (say scale=1). However, if I keep the loc variable as zero, I am not able to fix the scale at one. Is there some workaround for this? Can I not parametrize the gamma distribution using only the shape and scale?

推荐答案

在一条评论中,我说您在gamma发行版中遇到了一个错误-它不能同时固定位置和比例.该错误已在scipy 0.13中修复,但是如果无法升级,则可以使用类rv_continuousfit方法来解决该错误,该方法是gamma的父类:

In a comment I said you have run into a bug in the gamma distribution--it does not let you fix both the location and the scale. The bug was fixed in scipy 0.13, but if you can't upgrade, you can work around the bug by using the fit method of the class rv_continuous, which is the parent class of gamma:

In [22]: from scipy.stats import rv_continuous, gamma

In [23]: x = gamma.rvs(2.5, loc=0, scale=4, size=1000)  # A test sample.

In [24]: rv_continuous.fit(gamma, x, floc=0, fscale=4)
Out[24]: (2.5335837650122608, 0, 4)

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

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