Hyperparameter Tuning in R
Dr. Shirin Elsinghorst
Senior Data Scientist
Random Forest
...
Resampling results across tuning parameters:
mtry Accuracy Kappa
2 0.9006783 0.8015924
6 0.9126645 0.8253289
10 0.8999389 0.7999386
Accuracy was used to select the optimal model using the largest value.
The final value used for the model was mtry = 6.
modelLookup(model)
fitControl <- trainControl(method = "repeatedcv", number = 3, repeats = 5)
tic()
svm_model <- train(diagnosis ~ .,
data = bc_train_data,
method = "svmPoly",
trControl = fitControl,
verbose= FALSE)
toc()
3.836 sec elapsed
svm_model
Support Vector Machines with Polynomial Kernel
...
Resampling results across tuning parameters:
degree scale C Accuracy Kappa
1 0.100 1.00 0.9104803 0.8211459
Accuracy was used to select the optimal model using the largest value.
The final values used for the model were degree = 1, scale = 0.1 and C = 1.
tic()
set.seed(42)
svm_model_2 <- train(diagnosis ~ .,
data = bc_train_data,
method = "svmPoly",
trControl = fitControl,
verbose = FALSE,
tuneLength = 5)
toc()
7.458 sec elapsed
Accuracy was used to select the optimal model using the largest value.
The final values used for the model were degree = 1, scale = 1 and C = 1.
hyperparams <- expand.grid(degree = 4, scale = 1, C = 1)
tic() set.seed(42) svm_model_3 <- train(diagnosis ~ ., data = bc_train_data, method = "svmPoly", trControl = fitControl, tuneGrid = hyperparams, verbose = FALSE) toc()
0.691 sec elapsed
svm_model_3
Support Vector Machines with Polynomial Kernel
...
Accuracy Kappa
0.7772947 0.554812
Tuning parameter 'degree' was held constant at a value of 4
Tuning parameter 'scale' was held constant at a value of 1
Tuning parameter 'C' was
held constant at a value of 1
Hyperparameter Tuning in R