Machine Learning with caret in R
Max Kuhn
Software Engineer at RStudio and creator of caret
trainControl
object# Summarize the target variables
library(caret)
library(C50)
data(churn)
table(churnTrain$churn) / nrow(churnTrain)
yes no
0.1449145 0.8550855
# Create train/test indexes
set.seed(42)
myFolds <- createFolds(churnTrain$churn, k = 5)
# Compare class distribution
i <- myFolds$Fold1
table(churnTrain$churn[i]) / length(i)
yes no
0.1441441 0.8558559
myControl <- trainControl(
summaryFunction = twoClassSummary,
classProbs = TRUE,
verboseIter = TRUE,
savePredictions = TRUE,
index = myFolds
)
Machine Learning with caret in R