首页 > 解决方案 > CVXPY 在内核化套索上崩溃

问题描述

我正在尝试运行 CVXPY 来解决核化套索回归。

当预测变量的数量增加时(我的目标是拥有 3000 个),它会因“Killed”错误或“bad alloc”错误而崩溃。

import cvxpy as cp
import numpy as np
import scipy

np.random.seed(0)
NUM_PREDICTORS = 500
NUM_SAMPLES = 1
l1 = 10
x = np.random.randn(NUM_SAMPLES, NUM_PREDICTORS)
y = np.random.randn(NUM_SAMPLES, 1)
xx = x.T @ x
yx = y.T @ x
xx_sqrt = scipy.linalg.sqrtm(xx)
b = cp.Variable(yx.T.shape)
u = cp.sum_squares(xx_sqrt @ b) - cp.sum(2 * yx @ b) + l1 * cp.norm(b, 1)
obj = cp.Minimize(u)
prob = cp.Problem(obj)
prob.solve()
print('done')

标签: cvxpy

解决方案


推荐阅读