如何使用python将weibull分布拟合到数据中? [英] How to fit a weibull distribution to data using python?

查看:95
本文介绍了如何使用python将weibull分布拟合到数据中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找最适合使用 Python 3.4 的一组数据的 weibull 参数.

I am looking to find the best fit weibull parameters to a set of data using Python 3.4.

import scipy.stats as ss
list1 = []
list2 = []
for x in range(0, 10):
    list1.append(ss.exponweib.pdf(x, a=1, c=2.09, scale=10.895, loc=0))
    list2.append(ss.weibull_min.pdf(x, c=2.09, loc=0, scale=10.895))
    if list1[x]-list2[x] < .000000001:
        list1[x]=list2[x]

if list1 == list2:
    print("true")

print(ss.distributions.weibull_min.fit(list1, floc=0))
print(ss.distributions.weibull_min.fit(list1, loc=0))
print(ss.distributions.weibull_min.fit(list1, floc=0))
print(ss.distributions.exponweib.fit(list1, 1,1))
print(ss.distributions.exponweib.fit(list1, floc=0, f0=1))
print(ss.distributions.exponweib.fit(list1, floc=0, a=1, f0=1))

我尝试过的所有方法都没有产生输入参数,我不知道为什么.

Everything that I have tried doesn't yield the input parameters and I can't figure out why.

这段代码的输出是:

true
(2.8971366871403661, 0, 0.065615284314998634)
(0.71134622938358294, 0.014105558832066645, 0.076662586739229072)
(2.8971366871403661, 0, 0.065615284314998634)
(0.27753056922336583, 3.1962672780921197, -3.4788071110631162e-27, 0.077986010645321888)
(1, 2.8971366871403661, 0, 0.065615284314998634)
(1, 2.8971366871403661, 0, 0.065615284314998634)

没有一个是正确的输入参数.(2.09 和 10.895.)任何帮助表示赞赏.谢谢.

None of which are the correct input parameters. (2.09 and 10.895.) Any help is appreciated. Thanks.

推荐答案

fit() 方法的第一个参数是要拟合的分布中的值样本(不是 PDF 值).所以你应该使用 rvs() 方法来生成你的数据,而不是 pdf() 方法.

The first argument to the fit() method is a sample of values from the distribution to be fit (not PDF values). So you should use the rvs() method to generate your data, not the pdf() method.

这是一个简单的例子,我从 exponweib 分布中生成一个包含 250 个值的样本,然后在该样本上使用 fit().我假设当我拟合数据时,我知道形状参数 a 必须为 1,loc 参数必须为 0:

Here's a simple example where I generate a sample of 250 values from the exponweib distribution, and then use fit() on that sample. I'll assume that when I fit the data, I know that that the shape parameter a must be 1 and the loc parameter must be 0:

In [178]: from scipy.stats import exponweib

In [179]: sample = exponweib.rvs(a=1, c=2.09, scale=10.895, loc=0, size=250)

In [180]: exponweib.fit(sample, floc=0, fa=1)
Out[180]: (1, 2.0822583185068915, 0, 10.946962241403902)

这篇关于如何使用python将weibull分布拟合到数据中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆