gpt4 book ai didi

python - numpy.linalg.linalg.LinAlgError : SVD did not converge

转载 作者:行者123 更新时间:2023-11-28 20:45:27 27 4
gpt4 key购买 nike

这是我的 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

怎么了?

最佳答案

模型中的权重未以任何方式归一化。您传递了负权重,正如文档字符串所说,使用了权重的平方根。这引入了 NaN,这通常表明 SVD 收敛失败。

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com