4

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.

The output of this code is:

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)

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

1 Answer 1

6

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.

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.