0

I am using random forest and support vector machine method in caret package in R. I want to calculate AUC under ROC for both cases; however, I do not know how to do it in this particular case. My outcome is coded as 0 and 1. Here is the example of code I am using :

set.seed(123)
cvCtrl <- trainControl(method = "cv", number = 10)
rf_moded<-train(readm30~.,data=train,method="rf", trControl=cvCtrl)
Violeta
  • 1
  • 2
  • 1
    You need to obtain predicted probabilities from your model and not predicted classes. If you predict 0/1 and your target variable is 0/1 you can't plot a curve. You can only create a confusion matrix. You need your predictions to cover [0,1] (i.e. probabilities). This will help: https://stackoverflow.com/questions/30366143/how-to-compute-roc-and-auc-under-roc-after-training-using-caret-in-r?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – AntoniosK May 24 '18 at 13:58

1 Answers1

0

Do you want to train the model with ROC? Then you need the following:

For trainControl:

control <- trainControl(method = 'cv', number = 10, 
  savePredictions = 'final', classProbs = TRUE, summaryFunction = twoClassSummary)

And in train:

train(
  outcome ~ .,
  data = data,
  method = method,
  trControl = control,
  metric = "ROC"
)
tmastny
  • 417
  • 6
  • 11