我试图适应你的数据
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import genextreme as gev
def main(rvs):
shape, loc, scale = gev.fit(rvs)
return shape, loc, scale
if __name__ == '__main__':
rvs = [9.4, 38.0, 12.5, 35.3, 17.6, 12.9, 12.4, 19.6, 15.0, 13.2, 12.3, 16.9, 16.9, 29.4, 13.6, 11.1, 8.0, 16.6, 12.0, 13.1, 9.1, 9.7, 21.0, 11.2, 14.4, 18.8, 14.0, 19.9, 12.4, 10.8, 21.6, 15.4, 17.4, 14.8, 22.7, 11.5, 10.5, 11.8, 12.4, 16.6, 11.7, 12.9, 17.8]
shape, loc, scale = main(rvs)
print(shape)
print(loc)
print(scale)
l = loc + scale / shape
xx = np.linspace(l+0.00001, l+0.00001+35, num=71)
yy = gev.pdf(xx, shape, loc, scale)
hist, bins = np.histogram(rvs, bins=12, range=(-0.5, 23.5), density=True)
plt.bar(bins[:-1], hist, width = 2, align='edge')
plt.plot(xx, yy, 'ro')
plt.show()
但我得到的是
-0.21989526255575445
12.749780017954315
3.449061347316184
for shape
, loc
and scale
。如果你看scipy 中定义的 GEV 分布 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.genextreme.html,当shape为负数时,有效区间为[loc + scale/shape...+infinity]。我计算了后一个值,它等于
-2.935417290135696
应该管用...
Python3、Anaconda、scipy 1.1、Windows 10 64 位
UPDATE
好的,我已经更新了代码并添加了绘图,看起来有些合理。这是您要找的吗?基本上,技巧是对其进行直方图绘制并绘制与 PDF 重叠的密度箱