Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate AUC in R?

Given a vector of scores and a vector of actual class labels, how do you calculate a single-number AUC metric for a binary classifier in the R language or in simple English?

Page 9 of "AUC: a Better Measure..." seems to require knowing the class labels, and here is an example in MATLAB where I don't understand

R(Actual == 1)) 

Because R (not to be confused with the R language) is defined a vector but used as a function?

like image 695
Andrew Avatar asked Feb 04 '11 21:02

Andrew


People also ask

How do you find the AUC of a ROC curve in R?

The roc() function takes the actual and predicted value as an argument and returns a ROC curve object as result. Then, to find the AUC (Area under Curve) of that curve, we use the auc() function. The auc() function takes the roc object as an argument and returns the area under the curve of that roc curve.

What is the AUC of a function?

The AUC can be defined as the probability that the fit model will score a randomly drawn positive sample higher than a randomly drawn negative sample. This is also equal to the value of the Wilcoxon-Mann-Whitney statistic. This function is a wrapper for functions from the ROCR package.


2 Answers

With the package pROC you can use the function auc() like this example from the help page:

> data(aSAH) >  > # Syntax (response, predictor): > auc(aSAH$outcome, aSAH$s100b) Area under the curve: 0.7314 
like image 167
J. Win. Avatar answered Sep 20 '22 05:09

J. Win.


The ROCR package will calculate the AUC among other statistics:

auc.tmp <- performance(pred,"auc"); auc <- as.numeric([email protected]) 
like image 41
semaj Avatar answered Sep 20 '22 05:09

semaj