numpy.linalg.linalg.LinAlgError:SVD没有收敛

时间:2014-05-08 05:07:12

标签: python arrays numpy statsmodels

这是我的numpy数组:

z 
[[  3.90311860e-322   1.83939721e-001]
 [  0.00000000e+000   1.83939721e-001]
 [  0.00000000e+000   9.96473555e-001]
 [  0.00000000e+000   1.83939721e-001]
 [  0.00000000e+000   1.03585447e+000]
 [  0.00000000e+000   1.83939721e-001]
 [  0.00000000e+000   1.83939721e-001]
 [  0.00000000e+000   9.41400244e-001]
 [  0.00000000e+000   1.01817846e+000]
 [  0.00000000e+000   1.83939721e-001]]
weights
[[ -1.76457791 -24.11966074]
 [ -2.69231436 -24.11966074]
 [-24.11966074  -2.0106293 ]
 [ -1.99135789 -24.11966074]
 [-24.11966074  -1.89735781]
 [ -2.01441034 -24.11966074]
 [ -2.37736986 -24.11966074]
 [-24.11966074  -2.19061707]
 [-24.11966074  -1.94675704]
 [ -1.5983523  -24.11966074]]
X
[[   0.     2.5  100. ]
 [   2.     5.    80. ]
 [  31.    50.   -11. ]
 [  -0.5    2.    90. ]
 [  30.    45.5  -11. ]
 [   1.5    2.5  101. ]
 [   1.2    4.    85. ]
 [  31.    52.   -10. ]
 [  30.    48.   -15. ]
 [   1.     2.5  113. ]]

当我这样做时

import sys
import numpy as np
import statsmodels.api as sm

    for y1, w in zip(z.T, weights.T): # building the parameters per j class
        temp_g = sm.WLS(y1, X, w).fit()

我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\app\Documents\Python Scripts\gentleboost_c.py", line 177, in <module>
    boost(X, y, 10, test3)
  File "C:\Users\app\Documents\Python Scripts\gentleboost_c.py", line 80, in boost
    temp_g = sm.WLS(y1, X, w).fit()  # Step 2(a)(ii)
  File "C:\Users\app\Anaconda\lib\site-packages\statsmodels\regression\linear_model.py", line 127, in fit
    self.pinv_wexog = pinv_wexog = np.linalg.pinv(self.wexog)
  File "C:\Users\app\Anaconda\lib\site-packages\numpy\linalg\linalg.py", line 1574, in pinv
    u, s, vt = svd(a, 0)
  File "C:\Users\app\Anaconda\lib\site-packages\numpy\linalg\linalg.py", line 1323, in svd
    raise LinAlgError('SVD did not converge')
numpy.linalg.linalg.LinAlgError: SVD did not converge

出了什么问题?

1 个答案:

答案 0 :(得分:6)

权重未以任何方式在模型中标准化。您传递了负权重,并且如文档字符串所示,使用权重的sqrt。这引入了NaN,这通常是SVD收敛失败所表明的。