I have some models, using ROCR
package on a vector of the predicted class percentages, I have a performance object. Plotting the performance object with the specifications "tpr", "fpr" gives me a ROC curve.
I'm comparing models at certain thresholds of false positive rate (x). I'm hoping to get the value of the true positive rate (y) out of the performance object. Even more, I would like to get the class percentage threshold that was used to generate that point.
the index number of the false positive rate (x-value
) that is closest to the threshold without being above it, should give me the index number of the appropriate true positive rate (y-value
). I'm not exactly sure how to get that index value.
And more to the point, how do i get the threshold of class probabilities that was used to make that point?
2 solutions based on the
ROCR
andpROC
packages:See also
OptimalCutpoints
package which provides many algorithms to find an optimal thresholds.Package
pROC
includes functioncoords
for calculating best threshold:This is why
str
is my favorite R function:Ahah! It's an S4 class, so we can use
@
to access the slots. Here's how you make adata.frame
:If you have an fpr threshold you want to hit, you can subset this
data.frame
to find maximum tpr below this fpr threshold: