没有看到数据很难确定,但您的结果表明了几件事。
首先,AUC ROC 为 1。二元分类模型的 AOC ROC 为 1 表明该模型完全能够区分这两个类别。这可能是过度拟合的情况,也可能是您只有线性可分的类。
其次,不同惩罚值的恒定度量值。对于 LASSO 模型,随着惩罚的增加,越来越多的变量将缩小为零。在您的情况下,对于所有惩罚值(如果您关注帖子,它将是 10^(-4) 到 10^(-1)),您会看到相同的表现。这意味着即使您使用10^(-1) 的惩罚,您仍然没有缩小足够的预测变量来伤害/改变性能。下面的代表
set.seed(1234)
library(tidymodels)
response <- rep(c(0, 10), length.out = 1000)
data <- bind_cols(
response = factor(response),
map_dfc(seq_len(50), ~ rnorm(1000, response))
)
data_split <- initial_split(data)
data_train <- training(data_split)
data_test <- testing(data_split)
lasso_spec <- logistic_reg(mixture = 1, penalty = tune()) %>%
set_engine("glmnet")
lasso_wf <- workflow() %>%
add_model(lasso_spec) %>%
add_formula(response ~ .)
data_folds <- vfold_cv(data_train)
param_grid <- tibble(penalty = 10^seq(-4, -1, length.out = 30))
tune_res <- tune_grid(
lasso_wf,
resamples = data_folds,
grid = param_grid
)
autoplot(tune_res)
您可以做的是扩大处罚范围,直到您的表现发生变化。下面我们看到,一旦惩罚足够高,最后一个重要的预测变量就会缩小到零,我们就会失去性能。
param_grid <- tibble(penalty = 10^seq(-1, 0, length.out = 30))
tune_res <- tune_grid(
lasso_wf,
resamples = data_folds,
grid = param_grid
)
autoplot(tune_res)
为了验证,我们使用一种良好的性能惩罚来拟合模型,并得到完美的预测。
lasso_final <- finalize_workflow(lasso_wf, select_best(tune_res))
lasso_final_fit <- fit(lasso_final, data = data_train)
augment(lasso_final_fit, new_data = data_train) %>%
conf_mat(truth = response, estimate = .pred_class)
#> Truth
#> Prediction 0 10
#> 0 375 0
#> 10 0 375
由reprex package (v2.0.0) 于 2021-05-08 创建