cvxpy - 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')
解决方案
推荐阅读
- constructor - 学习 Python 中的构造函数
- playwright - 拒绝浏览器上的相机权限
- python - 如何模拟从熊猫中的示例函数返回的值?
- c++ - 关于unique_ptr所有权转移的问题
- reactjs - 导入多个 React 组件
- sql - 为什么在 sql server 中基于聚集索引的第二个键搜索并不能提高性能?
- python - 你如何为名为 makeWordLengthDict 的函数编写一个程序,该函数将单词列表作为其唯一参数,并在 python 中返回一个字典
- embedded-linux - 如何在 AST2500 上启用 USB 2.0 主机?
- java - 如何从 Uber Cadence 中的 Java 代码获取打开/关闭的工作流列表?
- c++ - 如何在 Windows-10 上的 Visual Studio Code 中设置和配置 MongoDB C/C++ (11/17) 驱动程序