Tune hyperparameters manually
If you already know which hyperparameter values you want to set, you can also manually define hyperparameters as a grid. Go to modelLookup("gbm")
or search for gbm
in the list of available models in caret and check under Tuning Parameters.
Note: Just as before,bc_train_data
and the libraries caret
and tictoc
have been preloaded.
This exercise is part of the course
Hyperparameter Tuning in R
Exercise instructions
- Define the following hyperparameter grid for a Gradient Boosting Model: the number of trees as 200; the tree complexity as 1; the learning rate as 0.1 and the minimum number of training set samples in a node to commence splitting as 10.
- Apply the grid to the
train()
function ofcaret
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define hyperparameter grid.
hyperparams <- expand.grid(___ = 200,
___ = 1,
___ = 0.1,
___ = 10)
# Apply hyperparameter grid to train().
set.seed(42)
gbm_model <- train(diagnosis ~ .,
data = bc_train_data,
method = "gbm",
trControl = trainControl(method = "repeatedcv", number = 5, repeats = 3),
verbose = FALSE,
___ = hyperparams)