[英]LinAlgError: SVD did not converge in Linear Least Squares np.linalg.lstsq
I get the aforementioned error although I check that I have no missing or infinite values when trying to do linear regression with np.linalg.lstsq...Any thoughts?尽管我在尝试使用 np.linalg.lstsq 进行线性回归时检查是否没有缺失值或无限值,但我得到了上述错误......有什么想法吗? I do these regressions recursively and I printed the shape of X and Y and are always same but it raises the error in a specific iteration我递归地进行这些回归,我打印了 X 和 Y 的形状,并且总是相同,但它会在特定迭代中引发错误
---> 17 betas = np.linalg.lstsq(X,Y,rcond=None)[0]
18
19 res = Y - X.dot(betas)
<__array_function__ internals> in lstsq(*args, **kwargs)
~\anaconda3\lib\site-packages\numpy\linalg\linalg.py in lstsq(a, b, rcond)
2257 # lapack can't handle n_rhs = 0 - so allocate the array one larger in that axis
2258 b = zeros(b.shape[:-2] + (m, n_rhs + 1), dtype=b.dtype)
-> 2259 x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)
2260 if m == 0:
2261 x[...] = 0
~\anaconda3\lib\site-packages\numpy\linalg\linalg.py in _raise_linalgerror_lstsq(err, flag)
107
108 def _raise_linalgerror_lstsq(err, flag):
--> 109 raise LinAlgError("SVD did not converge in Linear Least Squares")
110
111 def get_linalg_error_extobj(callback):
LinAlgError: SVD did not converge in Linear Least Squares
There are two most common reasons for this error.此错误有两个最常见的原因。 One is when you have infinity or NaNs present in your data.一种是当您的数据中存在无穷大或 NaN 时。 You say you check for those but do you check on each iteration or only in the original data?你说你检查那些但你检查每次迭代还是只检查原始数据?
If that is not the issue then the other possible problem is that a set of linear equations can have 1 solution (think like a point between two intersecting lines), but it can also have no solutions (for example, parallel lines) or infinite number of solutions (two lines on top of each other).如果这不是问题,那么另一个可能的问题是一组线性方程可以有一个解(就像两条相交线之间的一个点),但它也可以没有解(例如,平行线)或无限数解决方案(两条线相互重叠)。 The latter two situations should also trigger this error since the function cannot come up with a definitive answer.后两种情况也应该触发此错误,因为 function 无法得出明确的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.