代码之家  ›  专栏  ›  技术社区  ›  Vajira Prabuddhaka

statsmodels.discrete.discrete_model.negativeBinomial.fit()引发线性错误:“奇异矩阵”

  •  0
  • Vajira Prabuddhaka  · 技术社区  · 6 年前

    我在用 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
    

    有人能帮我修一下吗?是吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   sacuL    6 年前

    我认为这是一个过度参数化的问题。看来你有276个样本,有252个特征,这意味着对于一个小样本来说,模型太复杂了。这个 Singular matrix 警告表示该模型未找到与此模型的最佳收敛性。

    我会回去找出一个小得多的功能,你对建模感兴趣。