Using custom trainControl
Now that you have a custom trainControl
object, it's easy to fit caret
models that use AUC rather than accuracy to tune and evaluate the model. You can just pass your custom trainControl
object to the train()
function via the trControl
argument, e.g.:
train(<standard arguments here>, trControl = myControl)
This syntax gives you a convenient way to store a lot of custom modeling parameters and then use them across multiple different calls to train()
. You will make extensive use of this trick in Chapter 5.
This exercise is part of the course
Machine Learning with caret in R
Exercise instructions
- Use
train()
to predictClass
from all other variables in theSonar
data (that is,Class ~ .
). It should be aglm
model (that is, setmethod
to"glm"
) using your customtrainControl
object,myControl
. Save the result tomodel
. - Print the model to the console and examine its output.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Train glm with custom trainControl: model
# Print model to console