我正在使用逻辑回归进行 Mnist 数字分类,并且正在使用 statsmodel.api 库来拟合参数,但 Logit.fit() 仍然会引发溢出警告。以下是我在 Windows10、python 2.7 上使用从http下载的库时遇到的错误://www.lfd.uci.edu/~gohlke/pythonlibs/。
C:\Python27\lib\site-packages\statsmodels\discrete\discrete_model.py:1213: RuntimeWarning: overflow encountered in exp return 1/(1+np.exp(-X)) C:\Python27\lib\site-packages\statsmodels\discrete\discrete_model.py:1263: RuntimeWarning: divide by zero encountered in log return np.sum(np.log(self.cdf(q*np.dot(X,params)))) Warning: Maximum number of iterations has been exceeded.
Current function value: inf
Iterations: 35 Traceback (most recent call last): File "code.py", line 44, in <module>
result1 = logit1.fit() File "C:\Python27\lib\site-packages\statsmodels\discrete\discrete_model.py", line 1376, in fit
disp=disp, callback=callback, **kwargs) File "C:\Python27\lib\site-packages\statsmodels\discrete\discrete_model.py", line 203, in fit
disp=disp, callback=callback, **kwargs) File "C:\Python27\lib\site-packages\statsmodels\base\model.py", line 434, in fit
Hinv = np.linalg.inv(-retvals['Hessian']) / nobs File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 526, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj) File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix") numpy.linalg.linalg.LinAlgError: Singular matrix