Blurryface
Blurryface

Reputation: 11

Set the number of thresholds for ROC curve R ROCR

I am using the roc.curve of the ROCR package which provides a beautiful plot that is colorized according to the used threshold

using this code

library(ROCR)
pred <- prediction(predicted, response)
perf <- performance( pred, "tpr", "fpr" )
plot( perf, colorize = TRUE)

enter image description here

This function plots the ROC curve automatically, and even if it tries to fit in other to find good threshold values, but I have no control over how many thresholds are used or the range of the thresholds picked.

I have found another roc.curve function from another package called ROSE find more here: https://www.rdocumentation.org/packages/ROSE/versions/0.0-4/topics/roc.curve

In this function I have the possibility to set a number of thresholds

library(ROSE)
roc.curve(response, predicted, plotit = TRUE, add.roc = FALSE, n.thresholds=100)

enter image description here

I was wondering if there is a similar option for the function in ROCR package. Thank you PS I was wondering too why my roc curves are not similar, as if the TPR(true positif rate) and FPR(false positif rate) have been inverted

Upvotes: 1

Views: 1142

Answers (1)

Calimo
Calimo

Reputation: 7959

You can't!

By definition, a ROC curve goes over all thresholds.

And shouldn't.

If you limit the number of thresholds you use, like the ROSE package seems to do, this is no longer a ROC curve.

The curve given by ROCR already contains all thresholds between -Inf and +Inf. There is no way you can add more thresholds to it.

Upvotes: 1

Related Questions