Building better training data to predict children in hotel bookings

Application exercise

Your Turn 1

Unscramble! You have all the steps from our knn_rec- your challenge is to unscramble them into the right order!

Save the result as knn_rec

step_normalize(all_numeric())

recipe(children ~ ., data = hotels)

step_rm(arrival_date)

step_date(arrival_date)

step_downsample(children)

step_holiday(arrival_date, holidays = holidays)

step_dummy(all_nominal_predictors())

step_zv(all_predictors())

Your Turn 2

Fill in the blanks to make a workflow that combines knn_rec and with knn_mod.

knn_wf <- ______ |> 
  ______(knn_rec) |> 
  ______(knn_mod)
knn_wf

Your Turn 3

Edit the code chunk below to fit the entire knn_wflow instead of just knn_mod.

set.seed(100)
knn_mod |> 
  fit_resamples(children ~ ., 
                resamples = hotels_folds,
                # print progress of model fitting
                control = control_resamples(verbose = TRUE)) |> 
  collect_metrics()

Your Turn 4

Turns out, the same knn_rec recipe can also be used to fit a penalized logistic regression model using the lasso. Let’s try it out!

plr_mod <- logistic_reg(penalty = .01, mixture = 1) |> 
  set_engine("glmnet") |> 
  set_mode("classification")

plr_mod |> 
  translate()

Acknowledgments