Fitting distribution with fixed parameters in SciPy

僤鯓⒐⒋嵵緔 提交于 2019-12-31 02:26:30

问题


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)

results in non-zero location (loc).

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.


回答1:


To fix loc, use the argument floc:

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

E.g.

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)

Some related questions:

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


来源:https://stackoverflow.com/questions/21610034/fitting-distribution-with-fixed-parameters-in-scipy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!