4
$\begingroup$

I noticed that computing ROC with caret package and PROC packege sometimes gives different results. Usually they are the same, but if the predictions are worse than chance, caret will flip them and output 1 - ROC from PRROC. However there is sometimes exception when PRROC = 1-caret's.

example data and code:

library(caret)
library(PRROC)

# True labels
obs  <- c("c2", "c1", "c1", "c2", "c2", "c1", "c2", "c1", "c1")
# Probability of class1
c1 <- c(0.968, 0.282, 0.940, 0.940, 0.532, 0.312, 0.308, 0.730, 0.676)
# probability of class2
c2 <- 1 - c1
# actual prediction
pred <- c("c1", "c2", "c1", "c1", "c1", "c2", "c2", "c1", "c1")
dat1  <- data.frame(obs = obs, c1 = c1, c2 = c2, pred = pred)

obs  <- c("c2", "c1", "c2", "c2", "c1", "c1", "c1", "c2", "c1")
c1 <- c(0.622, 0.816, 0.662, 0.400, 0.434, 0.634, 0.550, 0.500, 0.482)
c2   <- 1 - c1
pred <- c("c1", "c1", "c1", "c2", "c2", "c1", "c1", "c2", "c2")
dat2 <- data.frame(obs = obs, c1 = c1, c2 = c2, pred = pred)

dat <- dat1
#caret ROC
twoClassSummary(dat, lev = c("c1", "c2")) 
# -> ROC 0.625
#PRROC ROC
roc.curve(dat[dat$obs == "c1", "c1"], dat[dat$obs == "c2", "c1"]) 
# -> ROC 0.375 

dat <- dat2
twoClassSummary(dat, lev = c("c1", "c2"))
# -> ROC 0.45 
roc.curve(dat[dat$obs == "c1", "c1"], dat[dat$obs == "c2", "c1"])
# -> 0.55 

Can ROC be < 0.5? Which package should I use? I suppose caret will artificially inflate ROC in cross-validation if there is no signal in the data.

$\endgroup$
4
  • $\begingroup$ What is the second package? PRROC? PROC? I can find neither on CRAN... $\endgroup$
    – Calimo
    Commented Oct 15, 2015 at 16:00
  • $\begingroup$ @user777 pROC does not have a roc.curve function as far as I know. $\endgroup$
    – Calimo
    Commented Oct 15, 2015 at 17:18
  • $\begingroup$ it's PRROC (two 'R'), I fixed it $\endgroup$
    – rep_ho
    Commented Oct 15, 2015 at 18:43
  • $\begingroup$ caret uses the pROC package to do the computation. $\endgroup$
    – topepo
    Commented Oct 16, 2015 at 15:54

1 Answer 1

3
$\begingroup$

ROC can be worse than 0.5. When ROC < 0.5, if you reverse the model recommendation, (i.e. if the model is so bad it recommends all 0 as 1 and all 1 as 0) you can turn a bad classifier into a better one. So that's what caret is doing.

To be clear, I'm not advising that this is good practice or recommended for any particular purpose -- I actually think that reversing recommendations based on AUC can be incredibly deceptive, and can conceal tremendous flaws with a model.

$\endgroup$
2
  • 2
    $\begingroup$ yes, but if you have random data, then your mean AUC for cv would not be 0.5 but something more, because always when it is smaller then 0.5 it would flip it. $\endgroup$
    – rep_ho
    Commented Oct 15, 2015 at 14:23
  • 1
    $\begingroup$ Yep, that's exactly right. To be clear, I'm not advising that this is good practice or recommended for any particular purpose -- I actually think that reversing recommendations based on AUC can be incredibly deceptive, and can conceal tremendous flaws with a model. $\endgroup$
    – Sycorax
    Commented Oct 15, 2015 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.