在我的数据集aps1中,我的目标变量是类,我有50个独立的功能。我运行以下代码来运行模型:
import numpy as np
import statsmodels.api as sm
model1= sm.Logit(aps1['class'],aps1.iloc[:,1:51])
这很好用。现在,在尝试拟合预测值时:
result = model1.fit()
我收到以下错误:
LinAlgError: Singular matrix
有人可以向我解释一下这里可以做些什么?感谢。
编辑:这就是我得到的:
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py:1214: RuntimeWarning: overflow encountered in exp
return 1/(1+np.exp(-X))
C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py:1264: 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 "<ipython-input-322-923286aab244>", line 1, in <module>
result = model1.fit()
File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py", line 1377, in fit
disp=disp, callback=callback, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\discrete\discrete_model.py", line 204, in fit
disp=disp, callback=callback, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\base\model.py", line 458, in fit
Hinv = np.linalg.inv(-retvals['Hessian']) / nobs
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 513, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\linalg\linalg.py", line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
LinAlgError: Singular matrix