Determine Weibull parameters from data
Asked Answered
E

1

6

I would like to identify the Weibull parameters (i.e. the shape and scale) of my data.

0.022988506
0.114942529
0.218390805
0.114942529
0.149425287
0.114942529
0.068965517
0.068965517
0.034482759
0.022988506
0.022988506
0.022988506
0.022988506

I've already tried what this answer proposed, and I'm using Python 3.4.

import scipy.stats as s
import numpy as np
from scipy import stats


def weib(x,n,a):
    return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)


data = np.loadtxt("data1.csv")
print(data)
(loc, scale) = s.exponweib.fit_loc_scale(data, 1, 1)
print('loc is: ',loc, '\n scale is: ', scale)

This gives me the following output:

[0.02298851  0.11494253  0.2183908   0.11494253  0.14942529  0.11494253   0.06896552  0.06896552  0.03448276  0.02298851  0.02298851  0.02298851 0.02298851]
loc is:  0.0574417296258 
scale is:  0.0179259738449

I assume that the data in my csv file was read as x-input values, instead of the y-values of the Weibull function. When I add a second column (or row) with bin, it gives an error that string values can not be converted into floats.

How do I need to modify my csv file in order to use the data within as the y-values of the Weibull function?

I think my problem might be that I don't understand this line:

(loc, scale) = s.exponweib.fit_loc_scale(data, 1, 1)

What does 1, 1 represent here? The parameters should then not be negative.

Emmeram answered 11/10, 2015 at 22:18 Comment(2)
When you say you want "the Weibull parameters", do you mean the parameters of the Weibull distribution (en.wikipedia.org/wiki/Weibull_distribution)? It has three parameters: a shape parameter, plus the location and scale parameters. exponweib is the exponentiated Weibull distribution (en.wikipedia.org/wiki/Exponentiated_Weibull_distribution), which has four parameters (two shape plus location and scale).Cabriolet
yes, it was meant the 2-parameter-weibull distribution f(x;λ,k), so adapting only shape and scale factors (λ, k). in that case, I shouldnt use exponweib, what to use instead?Emmeram
C
8

It looks like you want to use the fit method of scipy.stats.weibull_min (which is an alias for scipy.stats.frechet_r). Use the argument floc=0 to constrain the location to be 0.

In [9]: data
Out[9]: 
array([ 0.02298851,  0.11494253,  0.2183908 ,  0.11494253,  0.14942529,
        0.11494253,  0.06896552,  0.06896552,  0.03448276,  0.02298851,
        0.02298851,  0.02298851,  0.02298851])

In [10]: from scipy.stats import weibull_min

In [11]: shape, loc, scale = weibull_min.fit(data, floc=0)

In [12]: shape
Out[12]: 1.3419930069121602

In [13]: scale
Out[13]: 0.084273047253525968
Cabriolet answered 12/10, 2015 at 10:48 Comment(3)
Hi Warren. I used the same function to fit my data. But when I tend to constrain the 'loc' to zero, the returned loc is 0.999999 while my data's min value is 1. I also tried to constrain the shape parameter to 1 that the distribution will reduce to exponential model, the returned shape parameter is not 1(0.72~). So does it mean that the constrained params for input is not into usage for fit the model ? Can I suppose that all the three parameters are unique for a specified data ? Thanks.Mercy
@Mercy That is too much to discuss in these comments. You should start a new question.Cabriolet
Could you please provide an answer for my question. Much thanks to you.#43992299Mercy

© 2022 - 2024 — McMap. All rights reserved.