How to do it...

Perform the following steps to generate an ROC curve of each fitted model:

  1. Install and load the library, pROC:
        > install.packages("pROC")
        > library("pROC")  
  1. Set up the training control with a 10-fold cross-validation in three repetitions:
        > control = trainControl(method = "repeatedcv",
        +                         number = 10,
        +                         repeats = 3,
        +                         classProbs = TRUE,
        +                         summaryFunction = twoClassSummary)  
  1. Then, you can train a classifier on the training dataset using glm:
        > glm.model= train(churn ~ .,
        +                     data = trainset,
        +                     method = "glm",
        +                     metric = "ROC",
        +                     trControl = control)  
  1. Also, you can train a classifier on the training dataset using svm:
 > svm.model= train(churn ~ ., + data = trainset, + method = "svmRadial", + metric = "ROC", + trControl ...

Get Machine Learning with R Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.