ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Feature Engineering in R

Ver curso

Instrucciones del ejercicio

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

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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 y ejecutar código