r - 用于多项分类的 cv.glmnet() 中运行的大型矩阵
问题描述
我正在研究一个样本数为 N=40 和特征 P=7130 的大型矩阵。我正在尝试适应cv.glmnet()
山脊,但在执行此操作时出现错误。
数据集的维度为 (40,7130)
cv.glmnet() 的代码如下:
ridge2_cv <- cv.glmnet(x, y,
## type.measure: loss to use for cross-validation.
type.measure = "deviance",
## K = 10 is the default.
nfold = 10,
## Multinomial regression
family = "multinomial",
## ‘alpha = 1’ is the lasso penalty, and ‘alpha = 0’ the ridge penalty.
alpha = 0)
这x
是包含 285160 个元素的大矩阵。y
是大小为 40 的多类响应变量,
当我运行上述函数时,我不断收到此错误。
Error in cbind2(1, newx) %*% (nbeta[[i]]) :
invalid class 'NA' to dup_mMatrix_as_dgeMatrix
In addition: Warning messages:
1: In lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, :
one multinomial or binomial class has fewer than 8 observations; dangerous ground
2: In lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, :
one multinomial or binomial class has fewer than 8 observations; dangerous ground
解决方案
您可以尝试使用 data.matrix() 作为矩阵而不是 as.matrix 吗?我记得尝试过类似的东西。
ridge2_cv <- cv.glmnet(data.matrix(x), y,
## type.measure: loss to use for cross-validation.
type.measure = "deviance",
## K = 10 is the default.
nfold = 10,
## Multinomial regression
family = "multinomial",
## ‘alpha = 1’ is the lasso penalty, and ‘alpha = 0’ the ridge penalty.
alpha = 0)
推荐阅读
- matlab - UNIX Matlab - 循环计算绘图,但在最后显示
- html - 移动设备上的引导导航栏行为
- amazon-web-services - 如何从爱尔兰地区的多个地区(弗吉尼亚北部和爱尔兰)获取 X-RAY 数据。我怎么能这样做?有什么建议吗?
- c# - 我是否违反了 DI 模式规则
- c# - AutoMapper,SelectMany 我得到各种元素编号
- excel - 复制一系列过滤的单元格
- java - !strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 209
- reactjs - 如何使用 mobx 观察可观察数组上的 object.property 变化
- kotlin - 如何在 WebUI 中渲染 StreamObserver (ktor + freemarker)
- node.js - 如何从我的服务器中忽略或删除 dns 缓存浏览器?