python - 使用 python scipy 将 Gamma 分布拟合到数据

标签 python statistics scipy gamma-distribution

我想为我的数据拟合一个 Gamma 分布,我使用它来做

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。有什么解决方法吗?我不能仅使用形状和尺度对 Gamma 分布进行参数化吗?

最佳答案

我在评论中说您在 gamma 分布中遇到了一个错误——它不允许您修复位置和比例。该错误已在 scipy 0.13 中修复,但如果您无法升级,则可以使用 rv_continuous 类的 fit 方法解决该错误,该类是父级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 - 使用 python scipy 将 Gamma 分布拟合到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18703262/

相关文章:

python - 使用 Pandas 实现替代解决方案 `transform`

python - 为 Python 模块组合 Windows 安装程序

php - 分发评分数据以增加标准偏差

c++ - 程序统计工具

python - 如何将多项式拟合到带有误差线的数据

Python - 具有稀疏结果的矩阵乘法

python - 我怎样才能将我的Python列表转换为另一种列表格式

r - 拟合 3 参数威 bool 分布

python - scipy -- 如何积分线性插值函数?

python - 使用针状三角形计算两个向量之间的角度