python - 使用 genextreme 和 weibull_min 将 Weibull 拟合到分布

标签 python r scipy distribution weibull

使用 SciPy,我尝试重现 this question 中的威 bool 拟合。当我使用 genextreme 时,我的合身度看起来不错功能如下:

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

data=np.array([37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,
               38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40,
               42.26,41.89,38.87,43.02,39.25,40.38,42.64,36.98,44.15,44.91,43.40,
               49.81,38.87,40.00,52.45,53.13,47.92,52.45,44.91,29.54,27.13,35.60,
               45.34,43.37,54.15,42.77,42.88,44.26,27.14,39.31,24.80,16.62,30.30,
               36.39,28.60,28.53,35.84,31.10,34.55,52.65,48.81,43.42,52.49,38.00,
               38.65,34.54,37.70,38.11,43.05,29.95,32.48,24.63,35.33,41.34])

shape, loc, scale  = genextreme.fit(data)

plt.hist(data, normed=True, bins=np.linspace(15, 55, 9))

x = np.linspace(data.min(), data.max(), 1000)
y = genextreme.pdf(x, shape, loc, scale)
plt.plot(x, y, 'c', linewidth=3)

参数为:(0.44693977076022462, 38.283622522613214, 7.9180988170857374) 。形状参数为正,对应Weibull wikipedia page上形状参数的符号。据我了解,这相当于 R 中的负形状参数?

看来genextreme自行决定分布是 Gumbel、Frechet 还是 Weibull。这里它选择了威 bool 。

现在我正在尝试用 weibull_min 重现类似的拟合。功能。我根据 this post 尝试了以下操作,但参数看起来与我使用 genextreme 得到的参数非常不同:

weibull_min.fit(data, floc=0) 

现在的参数是:(6.4633107529634319, 0, 43.247460728065136)

0形状参数?如果分布是威 bool 分布,那么它肯定应该是正数吗?

最佳答案

weibull_min.fit()返回的参数是(shape,loc,scale)loc 是位置参数。 (所有 scipy 发行版都包含位置参数,即使那些通常不使用位置参数的发行版也是如此。)weibull_min.fit 的文档字符串包含以下内容:

Returns
-------
shape, loc, scale : tuple of floats
    MLEs for any shape statistics, followed by those for location and
    scale.

您使用了参数 floc=0,因此,正如预期的那样,fit(data, floc=0) 返回的位置参数为 0。

关于python - 使用 genextreme 和 weibull_min 将 Weibull 拟合到分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765996/

相关文章:

python - 从多个文件访问和编辑字典

python - 手动实现bayern转RGB

python - 如何向 Qt Mainloop 添加函数

r - Shiny :在 numericInput 中右键单击时提供上下文菜单?

python - 根据字段名称值对numpy结构化数组中的值进行排序

python - 使用 Python 进行多元线性回归

python - 无法将下载的文件存储在相关文件夹中

r - 运行长度的累积和。这个循环可以矢量化吗?

R:根据另一列中的值从一列中的拆分字符串中检索数据

python - 当没有数据像素时对图像应用滤镜