ComeçarComece de graça

Tuning the penalty

Confident that Lasso is a sensible approach to reducing the number of features of your model while maintaining acceptable performance, you want to tune the model by choosing the best penalty value. A basic recipe along with the train and test splits are loaded in your environment.

Este exercício faz parte do curso

Feature Engineering in R

Ver curso

Instruções do exercício

  • Set up your model so that the penalty is tuned automatically.
  • Configure a penalty grid with 30 levels.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Set up your model so that the penalty is tuned automatically
model_lasso_tuned <- logistic_reg() %>% set_engine("glmnet") %>%
  set_args(mixture = 1, ___ = ___) 
workflow_lasso_tuned <- workflow() %>%
  add_model(model_lasso_tuned) %>%
  add_recipe(recipe)

# Configure a penalty grid with 30 levels
penalty_grid <- grid_regular(penalty(range = c(-3, 1)), ___ = ___)

tune_output <- tune_grid(workflow_lasso_tuned,
  resamples = vfold_cv(train, v = 5),
  metrics = metric_set(roc_auc),grid = penalty_grid)

autoplot(tune_output)
Editar e executar o código