首先,我认为您可能希望将位置参数固定在0。在

其次,你的数据中有0,结果拟合可能在x=0处有{}pdf,例如对于GEV拟合或Weibull拟合。

因此,拟合实际上是正确的,但是当绘制pdf(包括x=0)时,得到的曲线图是扭曲的。在

第三,我真的认为scipy应该放弃对x=0的支持,比如Weibull。对于x=0,R给出了一个很好的Error in fitdistr(data, "weibull") : Weibull values must be > 0的警告,这很有帮助。在In [103]:

p=ss.genextreme.fit(data, floc=0)

ss.genextreme.fit(data, floc=0)

Out[103]:

(-1.372872096699608, 0, 0.011680600795499299)

In [104]:

plt.hist(data, bins=20, normed=True, alpha=0.7, label='Data')

plt.plot(np.linspace(5e-3, 1.6, 100),

ss.genextreme.pdf(np.linspace(5e-3, 1.6, 100), p[0], p[1], p[2]), 'r ',

label='GEV Fit')

plt.legend(loc='upper right')

plt.savefig('T1.png')

^{pr2}$

In [107]:

p=ss.weibull_min.fit(data[data!=0], floc=0)

ss.weibull_min.fit(data[data!=0], floc=0)

Out[107]:

(0.67366030738733995, 0, 0.10535422201164378)

In [108]:

plt.hist(data[data!=0], bins=20, normed=True, alpha=0.7, label='Data')

plt.plot(np.linspace(5e-3, 1.6, 100),

ss.weibull_min.pdf(np.linspace(5e-3, 1.6, 100), p[0], p[1], p[2]), 'r ',

label='Weibull_Min Fit')

plt.legend(loc='upper right')

plt.savefig('T3.png')

编辑

您的第二个数据(包含更多的0)是一个很好的例子,当涉及位置参数的MLE拟合变得非常困难时,尤其是在涉及大量浮点溢出/下溢的情况下:In [122]:

#fit with location parameter fixed, scanning loc parameter from 1e-8 to 1e1

L=[] #stores the Log-likelihood

P=[] #stores the p value of K-S test

for LC in np.linspace(-8, 1, 200):

fit = gev.fit(data, floc=10**LC)

L.append(np.log(gev.pdf(data, *fit)).sum())

P.append(kstest(data, 'genextreme', fit)[1])

L=np.array(L)

P=np.array(P)

In [123]:

#plot log likelihood, a lot of overflow/underflow issues! (see the zigzag line?)

plt.plot(np.linspace(-8, 1, 200), L,'-')

plt.ylabel('Log-Likelihood')

plt.xlabel('$log_{10}($'+'location parameter'+'$)$')

In [124]:

#plot p-value

plt.plot(np.linspace(-8, 1, 200), np.log10(P),'-')

plt.ylabel('$log_{10}($'+'K-S test P value'+'$)$')

plt.xlabel('$log_{10}($'+'location parameter'+'$)$')

Out[124]:

In [128]:

#The best fit between with location paramter between 1e-8 to 1e1 has the loglikelihood of 515.18

np.linspace(-8, 1, 200)[L.argmax()]

fit = gev.fit(data, floc=10**(np.linspace(-8, 1, 200)[L.argmax()]))

np.log(gev.pdf(data, *fit)).sum()

Out[128]:

515.17663678368604

In [129]:

#The simple MLE fit is clearly bad, loglikelihood is -inf

fit0 = gev.fit(data)

np.log(gev.pdf(data, *fit0)).sum()

Out[129]:

-inf

In [133]:

#plot the fit

x = np.linspace(0.005, 2, 200)

plt.plot(x, gev.pdf(x, *fit))

plt.hist(data,normed=True, alpha=0.6, bins=20)

Out[133]:

(array([ 8.91719745, 0.8492569 , 0. , 1.27388535, 0. ,

0.42462845, 0. , 0. , 0. , 0. ,

0. , 0. , 0. , 0. , 0. ,

0. , 0.42462845, 0. , 0. , 0.8492569 ]),

array([ 0. , 0.0785, 0.157 , 0.2355, 0.314 , 0.3925, 0.471 ,

0.5495, 0.628 , 0.7065, 0.785 , 0.8635, 0.942 , 1.0205,

1.099 , 1.1775, 1.256 , 1.3345, 1.413 , 1.4915, 1.57 ]),

)

编辑,GEV的拟合优度测试

关于KS测试的一个旁注。你正在测试一个GEV的拟合优度,它的参数是从数据本身估计出来的。在这种情况下,p值无效,请参见:itl.nist.gov/div898/handbook/eda/section3/eda35g.htm

关于GEV的拟合优度测试,似乎有很多研究,我还没有找到任何可用的实现。在

python广义极值_广义极值(GEV)极大似然拟合的奇异pdf相关推荐

  1. python广义极值_广义极值分布的数据拟合

    我一直想用scipy.stats.genextreme使我的数据符合广义极值分布.我试过所有我能找到的方法,但我不知道为什么它不符合数据.在 我试过这两种方法:import numpy as np f ...

  2. 结合泛函极值_泛函极值及变分法教程.doc

    PAGE PAGE 53 第二章 泛函极值及变分法(补充内容)2.1 变分的基本概念2.1.1 泛函和变分泛函是一种广义的函数,是指对于某一类函数{y(x)}中的每一个函数y(x),变量J有一值与之对 ...

  3. 结合泛函极值_泛函极值及变分法讲义.doc

    第二章 泛函极值及变分法(补充内容) 2.1 变分的基本概念 2.1.1 泛函和变分 泛函是一种广义的函数,是指对于某一类函数{y(x)}中的每一个函数y(x),变量J有一值与之对应,或者说数J对应于 ...

  4. 广义线性模型_广义线性模型(第六章补充)

    上一篇文章(第六章)主要介绍了最大熵模型,并从中推导出逻辑斯谛回归,感觉意犹未尽.在复习了CS229 Lecture note之后,我决定重新整理思路:从广义线性模型的角度来看逻辑斯谛回归.最后,基于 ...

  5. 结合泛函极值_泛函极值与变分法

    这篇文章是为了回答一位知友的提问而作的向未了解过变分法这个概念的读者介绍它的文章,因此本文只涉及一些变分法的入门知识.在从极值条件导出欧拉方程时只涉及泛函变分的Lagrange定义,这样一来就不必引入 ...

  6. Python使用sklearn构建广义线性模型:泊松回归(Poisson regression)实战

    Python使用sklearn构建广义线性模型:泊松回归(Poisson regression)实战 目录 Python使用sklearn构建广义线性模型:泊松回归(Poisson regressio ...

  7. Python使用sklearn构建广义线性模型:gamma回归(Gamma regression)实战

    Python使用sklearn构建广义线性模型:gamma回归(Gamma regression)实战 目录 Python使用sklearn构建广义线性模型:gamma回归(Gamma regress ...

  8. Python使用sklearn构建广义线性模型:Tweedie回归(Tweedie regression)实战

    Python使用sklearn构建广义线性模型:Tweedie回归(Tweedie regression)实战 目录 Python使用sklearn构建广义线性模型:Tweedie回归(Tweedie ...

  9. 一阶广义差分模型_广义差分法和自相关系数估计.ppt

    广义差分法和自相关系数估计 2. 广义差分法 广义差分法是将原模型变换为满足OLS法的差分模型,再进行OLS估计. 称(3)式为广义差分变换.(2)式可表示为: (4) 其中: (4)式是经广义差分变 ...

最新文章

  1. python map zip_python中的zip()函数和map()函数
  2. 面试的角度诠释Java工程师(一)
  3. python ssh模块_windows下python SSH的使用——paramiko模块
  4. linux用户、组、权限问题
  5. SSH框架整合实现Java三层架构实例(一)
  6. 用python模拟高斯分布
  7. java闰年的年份,Java案例-判断给定年份是闰年
  8. 2021吉林高考26日几点可以查询成绩,2021吉林高考成绩查分时间及入口
  9. Exchange2010安装过程中先决条件报错得处理方法
  10. android os苹果手机助手,深度系统V20(1003)内测招募:新增手机助手,支持安卓/iOS端...
  11. zookeeper3.4.6 使用研究
  12. hdu2112最短路径
  13. 面试官:new Object[5] 一共创建了几个对象?
  14. 定制Ubuntu桌面
  15. java 整形数据类型_3.2Java基本数据类型之整型
  16. java_web tomcat服务器的安装与配置
  17. delphi random_delphi产生随机数
  18. 苹果8a1660是什么版本_苹果a1780是什么版本
  19. sublime Boxy Theme安装方法
  20. 上海Apple面试php,面试Apple苹果APO的MQE经验

热门文章

  1. 歌单详情内容-播放列表 (音乐app项目-第8步)
  2. LuatIDE是什么?
  3. 带有en的单词有哪些_en押韵的词语
  4. Domino M-Series 设置说明
  5. 微信公众号的系统功能定位
  6. 如何关闭华为自动杀进程_如何彻底关闭windows 10的 自动更新
  7. Fluxion安装教程
  8. 使用idea构建父子类springboot项目教程,并教你启动子项目(构建项目集合)
  9. 微商城分销系统的怎么选择_有没有免费开源支持多端的_OctShop
  10. php excel水印图片大小,PHPExcel:如何在第一页标题中插入图像并将其放大以适合其内容?...