Scipy:使用loc=0,floc=0的fit有什么区别?

2024-09-24 22:23:12 发布

您现在位置:Python中文网/ 问答频道 /正文

当我拟合威布尔分布时,在其他问题中也发现了Fitting distribution with fixed parameters in SciPy

使用floc=0和{}进行拟合有区别

weibull_params = 1, 2.0755160030790547, 0, 16.273031221223277
data = sp.stats.exponweib.rvs(*weibull_params, size=50000)
data = data.astype(int)
x = linspace(0, 55)

weibull_params1 = sp.stats.weibull_min.fit(data)
weibull_params2 = sp.stats.weibull_min.fit(data, loc=0)
weibull_params3 = sp.stats.weibull_min.fit(data, floc=0)

for weibull_params, line_style in zip([weibull_params1, weibull_params2, weibull_params3],['-','--','-.']):
    plt.figure()
    plt.hist(data, bins=arange(0,55),alpha=0.5, normed=True)
    y_weibull = sp.stats.weibull_min.pdf(x, *weibull_params)
    plot(x, y_weibull, line_style, color='black') 
    print(weibull_params)

会产生这样的威布尔:

enter image description here

威布尔参数:

^{pr2}$

有什么区别?我什么时候该用哪一个?在


Tags: indatastylestatslineparamsminsp
1条回答
网友
1楼 · 发布于 2024-09-24 22:23:12

简单的回答是:floc(和fscale)用于指定位置参数(和比例参数)保持在指定值不变。loc和{}只给出拟合的起始值。在

sp.stats.weibull_minscipy.stat.rv_continuous继承fit方法。documentation of ^{}指定了一个事实,即floc和{}保持所述参数不变。locscale和其他由派生发行版识别的关键字参数被简单地用作起始值。在

因此,如果你想保持位置不变,你应该使用floc=0如果你只想提供一个起始参数,你应该使用loc=0。在

相关问题 更多 >