在SciPy中使用固定参数拟合分布 [英] Fitting distribution with fixed parameters in SciPy

查看:120
本文介绍了在SciPy中使用固定参数拟合分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在拟合SciPy中的分布时固定参数?例如,这段代码:

Is it possible to fix parameters while fitting distributions in SciPy? For example, this code:

import scipy.stats as st
xx = st.expon.rvs(size=100)
print st.expon.fit(xx, loc=0)

结果非零位置( loc )。

fit提供某些参数时函数被视为初始猜测。并且,如果将其提供给构造函数( st.expon(loc = 0)),则分配将变为冻结,不能用于拟合。

When some parameter is provided to the fit function it is considered as an initial guess. And if it is provided to the constructor (st.expon(loc=0)) the distribution becomes "frozen" and can not be used for fitting.

推荐答案

要修复 loc ,请使用参数 floc

print st.expon.fit(xx, floc=0)

例如

In [33]: import scipy.stats as st

In [34]: xx = st.expon.rvs(size=100)

In [35]: print st.expon.fit(xx, floc=0)
(0, 0.77853895325584932)

一些相关问题:

  • Gamma distribution fit error
  • Why does the Gamma distribution in SciPy have three parameters?
  • Fitting non-normpdf's to histograms in matplotlib

这篇关于在SciPy中使用固定参数拟合分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆