'AUC of a Precision Recall Curve by using package ROCR

How to obtain AUC (area under curve) of a Precision Recall Curve by using package ROCR..?

library(ROCR)
data(ROCR.simple)
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels)
perf <- performance(pred,"tpr","fpr")
plot(perf)
## precision/recall curve (x-axis: recall, y-axis: precision)
perf1 <- performance(pred, "prec", "rec")
plot(perf1)


Solution 1:[1]

You can first get the precision and recall values

x <- [email protected][[1]] # Recall values
y <- [email protected][[1]] # Precision values

and then calculate Area under the curve using any of the methods from calculate area under the curve

Solution 2:[2]

It looks like there are 2 measures for ROCR. auc and aucpr. This worked for me

For ROC

perfauc <- performance(pred, "auc")

For PR

perf1auc <- performance(pred, "aucpr")

Solution 3:[3]

ROCR can calculate AUC directly:

perf <- performance(pred, "auc")

Get AUC

[email protected][[1]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Levon Ipdjian
Solution 3 USER_1