cvxpy + mosek:指定的下限不是数字 (nan)

cvxpy + mosek: The lower bound specified is not a number (nan)

在下面的代码片段中,我尝试使用 cvxpy 和 mosek 求解器进行非常简单的线性回归

weight = df2['weight'].to_numpy()
A = df2[ regressors ].to_numpy()
x = cp.Variable(len(regressors ));
R = df2['y'].to_numpy()
cost = cp.sum_squares( A @ x - R)
print(A.shape, x.shape, R.shape)          # here it prints (134882, 8) (8,) (134882,)
prob = cp.Problem(cp.Minimize(cost), 
           [x >= 0])

但我总是报错。

Error: rescode.err_lower_bound_is_a_nan(1390): The lower bound specified is not a number (nan).

我已经查看了手册:https://docs.mosek.com/latest/pythonapi/response-codes.html#mosek.rescode.err_lower_bound_is_a_nan但是我到底错过了什么?

如果没有可重现的数据示例,很难回答这个问题。

您的 python 代码似乎没问题,所以我认为问题出在您的数据中:如果我必须猜测,我假设您的数据中某处有 NaNs 导致失败。

我不确定 cvxpy 和 mosek 是否完全可以处理 nans,因此最好在使用它们之前验证您的数据完整性。