以下是我的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

发生了什么?

最佳答案

权重在模型中没有以任何方式规范化。您传递了负权重,正如docstring所说,使用了权重的sqrt。这就引入了NaNs,这通常是SVD收敛失败的表现。

关于python - numpy.linalg.linalg.LinAlgError:SVD未收敛,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23533144/

10-13 21:37