Get startedGet started for free

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 customer
  • total_trans_amt: total sum of transactions in USD
  • customer_age: age of the customer
  • income_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.

This exercise is part of the course

Machine Learning with Tree-Based Models in R

View Course

Exercise instructions

  • Create three cross-validation folds of your dataset and save them as folds.
  • Create tune_results by tuning the specification along the grid using all predictors to predict still_customer, your CV folds as resamples, and metric_set(accuracy).
  • Use autoplot() to plot the tuning results.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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)
Edit and Run Code