2016-08-04 198 views
2

使用SciPy,我試圖從this question重現威布爾擬合。擬合威布爾與genextreme和weibull_min的分佈

import numpy as np 
from scipy.stats import genextreme 
import matplotlib.pyplot as plt 

data=np.array([37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00, 
       38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40, 
       42.26,41.89,38.87,43.02,39.25,40.38,42.64,36.98,44.15,44.91,43.40, 
       49.81,38.87,40.00,52.45,53.13,47.92,52.45,44.91,29.54,27.13,35.60, 
       45.34,43.37,54.15,42.77,42.88,44.26,27.14,39.31,24.80,16.62,30.30, 
       36.39,28.60,28.53,35.84,31.10,34.55,52.65,48.81,43.42,52.49,38.00, 
       38.65,34.54,37.70,38.11,43.05,29.95,32.48,24.63,35.33,41.34]) 

shape, loc, scale = genextreme.fit(data) 

plt.hist(data, normed=True, bins=np.linspace(15, 55, 9)) 

x = np.linspace(data.min(), data.max(), 1000) 
y = genextreme.pdf(x, shape, loc, scale) 
plt.plot(x, y, 'c', linewidth=3) 

的參數是:(0.44693977076022462, 38.283622522613214, 7.9180988170857374)當我使用genextreme功能如下我的配合看起來不錯。形狀參數是正的,對應於Weibull wikipedia page上的形狀參數的符號,據我所知,它相當於R中的負形狀參數。

因此,似乎genextreme自己決定分佈是Gumbel,Frechet還是Weibull。這裏選擇了Weibull。

現在我試圖重現與weibull_min函數類似的配合。我曾嘗試基於this post以下,但參數看我與genextreme有很大的不同:

weibull_min.fit(data, floc=0) 

的參數現在:(6.4633107529634319, 0, 43.247460728065136)

是在0形狀參數?如果分佈是Weibull,肯定會是正面的?

+0

無恥插件:paramnormal可能會幫助你在這裏:http://phobson.github.io/paramnormal/tutorial/fitting.html –

回答

1

weibull_min.fit()返回的參數是(shape, loc, scale)loc是位置參數。 (所有分佈SciPy的包括位置參數,甚至那些通常不使用的位置參數。)的weibull_min.fit的文檔字符串包括這樣的:

Returns 
------- 
shape, loc, scale : tuple of floats 
    MLEs for any shape statistics, followed by those for location and 
    scale. 

您使用的參數floc=0,因此,如所預期,位置參數由fit(data, floc=0)返回爲0.

+0

所以我用weibull_min.fit()得到的形狀參數是6.46。這與genextreme的0.44非常不同。並非43的比例參數相當高?如何使用weibull_min.fit()擬合數據曲線? –

+0

*關於值:*由weibull_min.fit(data,floc = 0)返回的值與R中fitdistr(mydata,「weibull」)'返回的值非常接近,正如您在鏈接問題中看到的那樣。 –