How to calculate the area under the ROC curve from the predicted class probabilities, in R using the pROC or ROCR package?

I used the carriage library to compute class probabilities and predictions for a binary classification problem using 10x cross validation and 5x repetition.

I now have TRUE values (observed values ​​for each data point), PREDICTED values (by algorithm), class 0 probabilities and class 1 probabilities , which were used by the algorithm to predict the class label.

Now how can I create an object roc

using a library ROCR

or pROC

and then calculate the value auc

?

Suppose I have all these values ​​stored in a predictions

dataframe. for example predictions$pred

and predictions$obs

are predicted and true values, respectively, and so on ...

+3


source to share


1 answer


Since you have not provided a reproducible example, I am assuming that you have a binary classification problem and you are predicting on Class

which Good

is either Bad

.

predictions <- predict(object=model, test[,predictors], type='prob')

      



You can do:

> pROC::roc(ifelse(test[,"Class"] == "Good", 1, 0), predictions[[2]])$auc
# Area under the curve: 0.8905

      

+5


source







All Articles