使 cv.glmnet select 介于 lambda.min 和 lambda.1se 之间
Make cv.glmnet select something between lambda.min and lambda.1se
我正在训练 Elastic Net 模型,发现 lambda.1se
比 lambda.min
高得多,通常是使用零特征 selected 测试的最大 lambda。我猜这是因为我的标准偏差真的很大。
有没有办法让 cv.glmnet
select 的值介于 lambda.1se
和 lambda.min
之间?
x = matrix(rnorm(100 * 20), 100, 20) # not the actual data
y = gl(2, 50)
fit <- cv.glmnet(
x = x, y = y,
family = "binomial",
nfolds = nrow(x), grouped = F,
standardize = T,
alpha = 0.2
)
感谢@Nutle,我能够使用您的建议实现类似于 caret
中的 tolerance
功能的选择功能。它在最小误差的百分比差异范围内选择 lambda 的最大值。
get_lambda <- function(fit, tol = 1.05) {
error <- fit$cvm[fit$lambda == fit$lambda.min]
tolerance <- error * tol
max(fit$lambda[fit$cvm <= tolerance])
}
我正在训练 Elastic Net 模型,发现 lambda.1se
比 lambda.min
高得多,通常是使用零特征 selected 测试的最大 lambda。我猜这是因为我的标准偏差真的很大。
有没有办法让 cv.glmnet
select 的值介于 lambda.1se
和 lambda.min
之间?
x = matrix(rnorm(100 * 20), 100, 20) # not the actual data
y = gl(2, 50)
fit <- cv.glmnet(
x = x, y = y,
family = "binomial",
nfolds = nrow(x), grouped = F,
standardize = T,
alpha = 0.2
)
感谢@Nutle,我能够使用您的建议实现类似于 caret
中的 tolerance
功能的选择功能。它在最小误差的百分比差异范围内选择 lambda 的最大值。
get_lambda <- function(fit, tol = 1.05) {
error <- fit$cvm[fit$lambda == fit$lambda.min]
tolerance <- error * tol
max(fit$lambda[fit$cvm <= tolerance])
}