10.5 Using Caret

The model can also be fit using caret. I’ll used LOOCV since the data set is so small. Normalize the variables to make their scale comparable.

library(caret)
library(kernlab)

train_data_3 <- train_data %>%
  mutate(y = factor(y, labels = c("A", "B")))

m4 <- train(
  y ~ .,
  data = train_data_3,
  method = "svmPoly",
  preProcess = c("center", "scale"),
  trControl = trainControl(
    method = "cv",
    number = 5,
    summaryFunction = twoClassSummary,	# Use AUC to pick the best model
    classProbs=TRUE
  )
)

m4$bestTune
##   degree scale   C
## 8      1   0.1 0.5
#plot(m4)