Fast Computation of ROC Curve in R
n <- 10^3 pred.x <- rnorm(n) true.x <- runif(n) < 1 / (1 + exp(-pred.x)) suppressPackageStartupMessages({ library(microbenchmark) library(ROCR) library(FastROC) library(pROC) library(caTools) }) f.ROCR <- function() { pred <- prediction(pred.x, true.x) perf <- performance(pred, "auc") perf@y.values[[1]] } f.FastROC <- function() { roc <- FastROC::ROC(true.x, pred.x) auc.RScupio <- FastROC::AUC(roc$x, roc$y) } f.pROC <- function() { g <- pROC::roc(true.x, pred.x) auc.pROC <- auc(g) } f.caTools <- function() { colAUC(pred.x, true.x)[1] } microbenchmark( auc.ROCR <- f.ROCR(), auc.FastROC <- f.FastROC(), auc.pROC <- f.pROC(), auc.caTools <- f.caTools() ) all.equal(auc.ROCR, auc.FastROC) all.equal(auc.pROC[1], auc.FastROC) all.equal(auc.caTools, auc.FastROC) n <- 10^4 pred.x <- rnorm(n) true.x <- runif(n) < 1 / (1 + exp(-pred.x)) microbenchmark(times=10, auc.ROCR <- f.ROCR(), auc.FastROC <- f.FastROC(), auc.pROC <- f.pROC(), auc.caTools <- f.caTools() ) n <- 10^5 pred.x <- rnorm(n) true.x <- runif(n) < 1 / (1 + exp(-pred.x)) microbenchmark(times = 10, auc.ROCR <- f.ROCR(), auc.FastROC <- f.FastROC(), auc.caTools <- f.caTools() ) print(auc.ROCR) print(auc.FastROC) print(auc.caTools) n <- 10^7 pred.x <- rnorm(n) true.x <- runif(n) < 1 / (1 + exp(-pred.x)) print(system.time(auc.ROCR <- f.ROCR())) print(system.time(auc.FastROC <- f.FastROC()))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.