我尝试运行RuntimeWarning: divide by zero encountered in log
时收到stats.boxcox(list)
错误。
该列表不包含零值。我已经提到了其他一些帖子,说我们可以使用np.errstate()
忽略错误。
但是,在我的情况下,我认为它不合适,因为stats.boxcox()
的值返回毫无意义(所有常数,见下文)。
array([ 0.11472901, 0.11472901, 0.11472901, 0.11472901, 0.11472901,
0.11472901, 0.11472901, 0.11472901, 0.11472901, 0.11472901,
0.11472901, 0.11472901, 0.11472901, 0.11472901, 0.11472901,
0.11472901, 0.11472901, ... ... ]
错误的详细信息如下:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/stats/morestats.py:591: RuntimeWarning: divide by zero encountered in log
llf -= N / 2.0 * np.log(np.sum((y - y_mean)**2. / N, axis=0))
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/optimize/optimize.py:2063: RuntimeWarning: invalid value encountered in double_scalars
w = xb - ((xb - xc) * tmp2 - (xb - xa) * tmp1) / denomenter code here
答案 0 :(得分:0)
我遵循了有关此Github线程的建议并为我工作:
https://github.com/scipy/scipy/issues/6873
建议使用stats.boxcox_normmax(array)
获得理想的lambda,然后进行boxcox
转换。
boxcox_lambda = boxcox_normmax(array, brack=(-1.9, 2.0), method='mle')
transformed_array = boxcox(array, boxcox_lambda)