Ajuste de hiperparâmetros com caret

Ajuste de hiperparâmetros em R

Dr. Shirin Elsinghorst

Senior Data Scientist

Ajuste automático de hiperparâmetros no caret

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.
Ajuste de hiperparâmetros em R

Hiperparâmetros são específicos de cada algoritmo

Ajuste de hiperparâmetros em R

Hiperparâmetros em Support Vector Machines (SVM)

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
Ajuste de hiperparâmetros em R

Hiperparâmetros em Support Vector Machines (SVM)

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.
Ajuste de hiperparâmetros em R

Definindo hiperparâmetros para ajuste automático

  • tuneLength
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.
Ajuste de hiperparâmetros em R

Ajuste manual de hiperparâmetros no caret

  • tuneGrid + expand.grid
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
Ajuste de hiperparâmetros em R

Ajuste manual de hiperparâmetros no caret

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
Ajuste de hiperparâmetros em R

É a sua vez!

Ajuste de hiperparâmetros em R

Preparing Video For Download...