Session Ready
Exercise

Tuning a Random Forest via tree depth

In Chapter 2, we created a manual grid of hyperparameters using the expand.grid() function and wrote code that trained and evaluated the models of the grid in a loop. In this exercise, you will create a grid of mtry, nodesize and sampsize values. In this example, we will identify the "best model" based on OOB error. The best model is defined as the model from our grid which minimizes OOB error.

Keep in mind that there are other ways to select a best model from a grid, such as choosing the best model based on validation AUC. However, for this exercise, we will use the built-in OOB error calculations instead of using a separate validation set.

Instructions
100 XP
  • Create a grid of mtry, nodesize and sampsize values.
  • Write a simple loop to train all the models and choose the best one based on OOB error.
  • Print the set of hyperparameters which produced the best model.