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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.