I have used ROCR package to plot a colorized roc curve. The curve itself does not have any problem and looks nice and fine but the palette shows that cutoff points are greater than 1 which is incorrect as these are probabilities and should be in the range of 0 to 1. I checked my dataset several times but it seems ok and there is nothing wrong with my dataset.
Here is the code along with the predictions values and their corresponding labels.here is the plotted roc curve for my classification
My initial guess is that there is a bug in the ROCR package but I'm not completely sure. Any help to figure it out would be appreciated.
library(ROCR)
labels <-c(1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
scores<-c(1,1,1,0.8,1,1,1,0.95,1,1,1,1,1,0,0,0,0,0,0,0.97,0,0,0,0,0,0,0,0,0,0,0,0.206,0)
pred<-prediction(scores,labels)
perf<-performance(pred,"tpr","fpr")
plot(perf,colorize=TRUE)
Seems you found a bug in ROCR
, caused by the first cutoff
being Inf
, which in turn causes the first entry of alpha.values
to be Inf
as well:
> attributes(pred)$cutoffs[[1]]
[1] Inf 1.000 0.970 0.950 0.800 0.206 0.000
> attributes(perf)$alpha.values[[1]]
[1] Inf 1.000 0.970 0.950 0.800 0.206 0.000
This would not be a problem so far, but it seems alpha.values
is used for colourization, which might cause for this strange behaviour. Setting the first entry to 1
instead of Inf
fixes the issue, which could be use as a quick fix to this problem:
> attributes(perf)$alpha.values[[1]][1] <- 1
> attributes(perf)$alpha.values[[1]]
[1] 1.000 1.000 0.970 0.950 0.800 0.206 0.000
> plot(perf,colorize=TRUE)