数据直方图的威布尔拟合

时间:2019-05-13 15:40:31

标签: python pandas matplotlib scipy

使用以下代码,我可以将数据的直方图和拟合曲线绘制到直方图上。

mybins = len(data)//20
fig, (ax) = plt.subplots(1,1, figsize=(5, 3))
(mu,sigma) = scipy.stats.norm.fit(data)
n,bins,patches=ax.hist(data, bins=mybins, density=True, color='green', histtype='stepfilled', linewidth=1) 
ax.axvline(x=data.mean(), color='green', linestyle='dashed', linewidth=3)
y = scipy.stats.norm.pdf(bins, mu, sigma)
ax.plot(bins,y,'r--',color='green', linewidth=3)
ax.set_xlim(0.5,1.1)

这是直方图及其均值垂直线正确的输出。
enter image description here

但是,拟合曲线是相对于平均值的正态拟合。
我需要帮助来实现 Weibull 拟合,该拟合将根据数据分布产生偏斜的拟合曲线。

尝试使用this中的以下内容:

shape, loc, scale = weibull_min.fit(data, floc=0)
plt.plot(data, stats.exponweib.pdf(data, *stats.exponweib.fit(data, 1, 1, scale=scale, loc=loc)))
plt.hist(data, label='PR', density=True, bins=len(data)//15, color = 'orangered')
plt.axvline(x=data.mean(), color='black', linestyle='dashed', linewidth=3)
plt.show()

结果是
enter image description here

修改
另一种尝试使用排序数据:

fig, (ax) = plt.subplots(1,1, figsize=(5, 3))
ax.hist(data, bins=len(data)//15, color = 'orangered')
shape, loc, scale = weibull_min.fit(data, floc=0)
plt.plot(data, stats.exponweib.pdf(data, *stats.exponweib.fit(data, 1, 1, scale=scale, loc=loc)))
plt.show()

现在的结果要好得多,但仍然不是应该的样子,即拟合曲线不适合直方图的“大小”。
enter image description here

我的数据可以从here下载。
感谢您的帮助。

0 个答案:

没有答案
相关问题