Scipy:使用loc = 0和floc = 0进行拟合之间有什么区别? [英] Scipy: What's the difference between fit using loc=0, floc=0?
问题描述
我正在拟合Weibull分布,并且在其他问题中也发现为在SciPy中使用固定参数拟合分布
As I'm fitting a Weibull distribution, and also find in other questions as Fitting distribution with fixed parameters in SciPy
使用floc=0
和loc=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)
将产生像这样的威布尔犬:
would produce the Weibull like these:
Weibull参数:
Weibull params:
(0.50240047370945606, -4.501644985259555e-28, 2.9918077253782287)
(2.0610053128948245, -0.45099484072568979, 16.299110670854041) #loc=0
(1.0, 0, 1.05) #floc=0
有什么区别?我什么时候应该使用哪个?
What is the difference? When should I use which one?
推荐答案
简短的答案是:floc
(和fscale
)用于指定location参数(和scale参数分别)用于保持固定在指定值. loc
和scale
仅给出拟合的起始值.
The short answer is: floc
(and fscale
for that matter) are used to specify that the location parameter (and scale parameter respectively) are to be kept fixed at the specified value. loc
and scale
merely give starting values for the fit.
sp.stats.weibull_min
从scipy.stat.rv_continuous
继承fit
方法. 文档scipy.stats.rv_continuous.fit
的值指定事实,即floc
和fscale
保持所述参数固定.派生分布识别的loc
,scale
和其他关键字参数仅用作起始值.
sp.stats.weibull_min
inherits the fit
method from scipy.stat.rv_continuous
. The documentation of scipy.stats.rv_continuous.fit
specifies the fact, that floc
and fscale
keep said parameters fixed. loc
, scale
and other keyword arguments that are recognized by derived distributions are simply used as starting values.
因此,如果要保持位置固定,则应使用floc=0
;如果仅想提供起始参数,则应使用loc=0
.
So if you want to fit keeping the location fixed, you should use floc=0
if you only want to provide a starting parameter, you should use loc=0
.
这篇关于Scipy:使用loc = 0和floc = 0进行拟合之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!