Tune along the grid
After creating the tuning grid and a dummy specification, you need to fit a model on every grid point and evaluate the resulting model.
This is very easy in the tidymodels framework using the tune_grid() function, as introduced in the slides.
In the remaining exercises, you will use the credit card customers dataset, which has the following columns:
still_customer: flag (yes or no) that indicates if a customer is still an active customertotal_trans_amt: total sum of transactions in USDcustomer_age: age of the customerincome_category: labels like $60K - $80K or Less than $40K to indicate the category of yearly income- … and 16 more columns.
Feel free to inspect the customers tibble in the console! The results of the previous exercise, tree_grid and tune_spec, are still loaded.
Cet exercice fait partie du cours
Machine Learning with Tree-Based Models in R
Instructions
- Create three cross-validation folds of your dataset and save them as
folds. - Create
tune_resultsby tuning the specification along the grid using all predictors to predictstill_customer, your CV folds as resamples, andmetric_set(accuracy). - Use
autoplot()to plot the tuning results.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
set.seed(275)
# Create CV folds of the customers tibble
folds <- ___
# Tune along the grid
tune_results <- tune_grid(___,
___,
resamples = ___,
grid = ___,
metrics = ___)
# Plot the tuning results
___(tune_results)