I'm trying to find a single method to give me AUC for a random forest model for both the training and testing sets without using MLeval.
Here's a good example for ROC on training data, and here's a good example for ROC on testing data. The first example for AUC for training data gives AUC=0.944.
plot.roc(rfFit$pred$obs[selectedIndices],
rfFit$pred$M[selectedIndices], print.auc=TRUE)
ctrl <- trainControl(method="cv",
summaryFunction=twoClassSummary,
classProbs=T,
savePredictions = T)
rfFit <- train(Class ~ ., data=Sonar,
method="rf", preProc=c("center", "scale"),
trControl=ctrl, metric="ROC")
print(rfFit)
...
mtry ROC Sens Spec
2 0.9459428 0.9280303 0.8044444
result.predicted.prob <- predict(rfFit, Sonar, type="prob") # Prediction
result.roc <- roc(Sonar$Class, result.predicted.prob$M)
plot(result.roc, print.thres="best", print.thres.best.method="closest.topleft", print.auc=TRUE)
But that AUC for the entire training data (i.e. Sonar) is 1.0, while rfFit shows 0.946 which is also different! So why am I getting different results and what's the correct way to calculate AUC for both training and testing?