gpt4 book ai didi

python - 如何在 python 中使用 alpha 和 beta 参数绘制 Gamma 分布

转载 作者:太空狗 更新时间:2023-10-29 22:12:34 25 4
gpt4 key购买 nike

我想绘制 alpha = 29(尺度)和 beta = 3(大小)的 Gamma 分布。换句话说,我想绘制 Gamma(29,3) 的 pdf。如果根据 documentation,我该怎么做, python gamma函数只有参数a和x而size参数不存在?

我以为 loc 是测试版,但我认为它实际上是偏移的,所以下面的代码是错误的...

import numpy as np
import scipy.stats as stats
from matplotlib import pyplot as plt

x = np.linspace (0, 100, 200)
y1 = stats.gamma.pdf(x, a=29, loc=3) #a is alpha, loc is beta???
plt.plot(x, y1, "y-", label=(r'$\alpha=29, \beta=3$'))


plt.ylim([0,0.08])
plt.xlim([0,150])
plt.show()

最佳答案

根据文档,您想使用比例参数 (theta),但由于您定义的是 beta,它是 theta 的倒数,因此您传递的比例值为 1/beta,在您的示例中为 1/3 或 0.33333。

因此,尝试:

y1 = stats.gamma.pdf(x, a=29, scale=0.33333)

关于python - 如何在 python 中使用 alpha 和 beta 参数绘制 Gamma 分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42150965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com