简体   繁体   中英

Fitting distribution with fixed parameters in 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)

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.

To fix loc , use the argument floc :

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

Eg

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM