【发布时间】:2017-11-19 09:58:15
【问题描述】:
如果我在 python 中运行以下代码
from scipy.stats import norm, beta
sample = beta.rvs(2,5,size=100)
beta_fit = beta.fit(sample)
我收到以下错误
/usr/lib/python3/dist-packages/scipy/stats/_continuous_distns.py:404: RuntimeWarning: invalid
value encountered in sqrt
sk = 2*(b-a)*sqrt(a + b + 1) / (a + b + 2) / sqrt(a*b)
根据样本的大小,我有时也会遇到其他错误
/usr/lib/python3/dist-packages/scipy/optimize/minpack.py:161: RuntimeWarning:
The iteration is not making good progress, as measured by the improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
有谁知道为什么会发生这种情况以及如何解决?
谢谢!
【问题讨论】:
-
仅供参考:Scipy 的 beta 分布有四个参数。有两个形状参数(wikipedia article 中的 α 和 β)。其他两个参数是location and scale;这些调整分布的support。默认情况下,
fit()方法认为所有四个参数都可用于拟合。那是你要的吗?还是只适合形状参数,并保持支持为 [0, 1]? -
我想保持支持为[0,1],我该如何强加?我假设 beta.fit 函数采用 loc=0 和 scale=1 的默认值。我错了吗?
-
默认情况下,
fit()在要拟合的参数中包含loc和scale。请参阅我的答案以了解如何保持这些固定。
标签: python python-3.x scipy statistics