我对Python非常陌生,我在互联网上四处寻找,但是找不到任何能帮助我解决问题的逻辑。
我有一个图中的降水值,现在我需要从图中的这些值中拟合一个GEV分布。每个值等于从1974年到2017年一年的最大值(因此总共有43个值)。
这些都是价值:
max_precip = [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]我发现我需要使用gev.fit,所以我想使用以下方法:
t = np.linspace(1,43,43)
fit = gev.fit(max_precip,loc=3)
pdf = gev.pdf(t, *fit)
plt.plot(t,pdf)
plt.plot(t, max_precip, "o")但是这只是在一个图中打印max_precip的点,而不是GEV分布。
有人能帮我吗?对不起,如果这个问题已经问过了,我什么也找不到。
我使用了这些进口产品:
import csv
import matplotlib.pyplot as plt
import numpy as np
from dateutil.rrule import rrule, YEARLY
import datetime
from matplotlib.dates import DateFormatter
from scipy.stats import genextreme as gev
from scipy.stats import genpareto as gpd
from scipy.optimize import minimize发布于 2018-09-22 19:21:40
我试着把你的数据
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.449061347316184shape,loc和scale。如果查看在枕中定义的GEV分布,当形状为负值时,有效间隔为loc +刻度/形状.+无穷大。我计算了后一个值,它等于
-2.935417290135696应该有效..。
Python3,Anaconda,枕1.1,Windows 10 64位
更新
好的,我已经更新了代码并添加了绘图,看起来有点合理。你在找什么?基本上,诀窍是将其直方图化,并将密度箱与PDF重叠。

发布于 2020-11-05 20:22:12
出于好奇,我尝试了GeneralizedExtremeValue工厂 (GEV)在OpenTURNS中的应用
import openturns as ot
sample = ot.Sample([[p] for p in max_precip])
gev = ot.GeneralizedExtremeValueFactory().buildAsGeneralizedExtremeValue(sample)
print (gev)
>>> GeneralizedExtremeValue(mu=12.7497, sigma=3.44903, xi=0.219894) 我可以确认它给出了同样的结果。

https://stackoverflow.com/questions/52455797
复制相似问题