我在用
statsmodels.discrete.discrete_model.NegativeBinomial
对于负二项回归任务,我使用以下脚本创建了一个模型:
from statsmodels.discrete.discrete_model import NegativeBinomial
#create a model
regr = NegativeBinomial(y_train, X_train)
这里我的
y_train
&安培
X_train
有类型
<class 'numpy.ndarray'>
形状像
(276,)
&安培
(276, 252)
分别是。
我的问题是当我打电话
regr.fit()
它提高了
numpy.linalg.linalg.LinAlgError: Singular matrix
错误。这是我的堆栈跟踪:
Traceback (most recent call last):
File "/home/vajira/PycharmProjects/dengAI/neg_binomial_custom.py", line 137, in <module>
regr_iq = regr_run(nptrain_iq, degree_iq, exploring=True)
File "/home/vajira/PycharmProjects/dengAI/neg_binomial_custom.py", line 92, in regr_run
regr.fit()
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py", line 2756, in fit
res_poi = mod_poi.fit(**optim_kwds_prelim)
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py", line 1034, in fit
disp=disp, callback=callback, **kwargs)
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py", line 220, in fit
disp=disp, callback=callback, **kwargs)
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/base/model.py", line 466, in fit
full_output=full_output)
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/base/optimizer.py", line 191, in _fit
hess=hessian)
File "/home/vajira/ipython/lib/python3.6/site-packages/statsmodels/base/optimizer.py", line 278, in _fit_newton
newparams = oldparams - np.dot(np.linalg.inv(H),
File "/home/vajira/ipython/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 528, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File "/home/vajira/ipython/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 89, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix
有人能帮我修一下吗?是吗?