lr_mod <- logistic_reg() |>
set_engine(engine = "glm") |>
set_mode("classification")
lr_modAE 14: Predicting children in hotel bookings
Your Turn 1
Run the chunk below and look at the output. Then, copy/paste the code and edit to create:
a decision tree model for classification
that uses the {C5.0} engine.
Save it as tree_mod and look at the object. What is different about the output?
Hint: you’ll need https://www.tidymodels.org/find/parsnip/
Your Turn 2
Fill in the blanks.
Use initial_split(), training(), and testing() to:
Split hotels into training and test sets. Save the
rsplit!Extract the training data and fit your classification tree model.
Check the proportions of the
testvariable in each set.
Keep set.seed(100) at the start of your code.
Hint: Be sure to remove every _ before running the code!
set.seed(100) # Important!
hotels_split <- ________(hotels, prop = 3 / 4)
hotels_train <- ________(hotels_split)
hotels_test <- ________(hotels_split)
# check distribution
count(x = hotels_train, children) |>
mutate(prop = n / sum(n))
count(x = hotels_test, children) |>
mutate(prop = n / sum(n))Your Turn 3
Run the code below. What does it return?
set.seed(100)
hotels_folds <- vfold_cv(data = hotels_train, v = 10)
hotels_foldsYour Turn 4
Add a autoplot() to visualize the ROC AUC. How well does the model perform?
tree_preds <- tree_mod |>
fit_resamples(
children ~ average_daily_rate + stays_in_weekend_nights,
resamples = hotels_folds,
control = control_resamples(save_pred = TRUE)
)
tree_preds |>
collect_predictions() |>
roc_auc(truth = children, .pred_children)
tree_preds |>
collect_predictions() |>
roc_curve(truth = children, .pred_children) |>
________()Add response here.
Acknowledgments
- Materials derived from Tidymodels, Virtually by Allison Hill and licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA) License.
- Dataset and some modeling steps derived from A predictive modeling case study and licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA) License.