4

I was totally confused by fitting a weibull distribution, by

weibull_params = sp.stats.exponweib.fit(df.speed, floc=0, f0=1)
# Returns (1, 1.7358162061451901, 0, 9.4955614228786978)

How do these params correspond to the Weibull Distribution in https://en.wikipedia.org/wiki/Weibull_distribution ? Specifically, what is a, c in wiki's lambda and k?

In http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.exponweib.html#scipy.stats.exponweib , the pdf is defined as

exponweib.pdf(x, a, c) =
    a * c * (1-exp(-x**c))**(a-1) * exp(-x**c)*x**(c-1)

But in Wikipedia, the PDF is

enter image description here


Also, I get different result if I use exponweib.pdf with the params it returns

df['speed'].hist(bins=arange(0, df.speed.max()), alpha=0.5, normed=True)

def weib(x,lamb,k):
    return (k / lamb) * (x / lamb)**(k-1) * np.exp(-(x/lamb)**k)
k_shape, lamb_scale = weibull_params[1], weibull_params[3]
plt.plot(x, weib(x, lamb_scale, k_shape), label='self-defined weibull')

plt.plot(x, sp.stats.exponweib.pdf(x, k_shape, lamb_scale, loc=0, scale=1),'--', label ='custom_order')
plt.legend()

enter image description here

B--rian
  • 5,578
  • 10
  • 38
  • 89
ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
  • https://en.wikipedia.org/wiki/Exponentiated_Weibull_distribution The regular Weibull is basically the exponentiated one with `alpha = 1`. Scipy's `a` seems to correspond to `alpha`. You'd need to figure out how `k` and `lambda` relate to Scipy's `scale` and `c` by comparing the equations for the two PDFs. – Salmonstrikes Jul 10 '16 at 02:43
  • See my answer here: http://stackoverflow.com/questions/33070724/determine-weibull-parameters-from-data/33079243#33079243 – Warren Weckesser Jul 10 '16 at 02:52
  • @WarrenWeckesser Is `weibull_min` and `weibull` the same? `weibull_min` only has a `c` in http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.weibull_min.html#scipy.stats.weibull_min – ZK Zhao Jul 11 '16 at 00:03
  • 6
    There is no distribution called `weibull` in scipy. There are `weibull_min`, `weibull_max` and `exponweib`. `weibull_min` is the one that matches the wikipedia article on the Weibull distribuition. `weibull_min` has three parameters: `c` (shape), `loc` (location) and `scale` (scale). `c` and `scale` correspond to *k* and λ in the wikipedia article, respectively. (They aren't shown in the formula in the docstring, but *all* the scipy distributions have `loc` and `scale` parameters.) – Warren Weckesser Jul 11 '16 at 01:05
  • I forgot, there is also `dweibull`, but that the *double* Weibull distribution, which is not the one that you want. – Warren Weckesser Jul 11 '16 at 01:38

0 Answers0