Pregunta

Here are my numpy arrays:

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. ]]

When I do

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()

I get the following error:

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

What's wrong?

¿Fue útil?

Solución

The weights aren't normalized in the model in any way. You passed negative weights and as the docstring says, the sqrt of weights is used. This introduces NaNs, which is usually what the SVD convergence failure indicates.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top