I have the prediction values of different algorithms, as shown below. My question is: how can I get the FPR and TPR to form a ROC curve? If I compute the confusion matrix I am getting only one point, but I can't get a curve from it.
TRUE FALSE
20 0.3804752 0.6195248
22 0.4220737 0.5779263
25 0.5292302 0.4707698
5 0.1566432 0.8433568
7 0.3121428 0.6878572
8 0.2075050 0.7924950
9 0.1507119 0.8492881
14 0.2217667 0.7782333
15 0.6088052 0.3911948
18 0.4402029 0.5597971
Best Answer
You need both the predicted class probabilities (as you have them in your example) and the observed = real class labels to compare your predictions to.
From those, the steps of computing a ROC curve are simple:
Compute the class predictions for all possible thresholds, using one of the predicted class probabilities as predictor. This means that probabilities being above the threshold become a $P$ prediction, and those below the threshold become an $N$ prediction. From those class predictions, compute the TPR and FPR (= 1-TNR) for the associated threshold. This means you will get one TPR and FPR rate per possible threshold value (which should be the difference to what you mentioned with the confusion matrix, which instead is computed just once using one desired threshold).
Print all the TPR values against the FPR value to obtain a ROC curve.
As you are aiming to do this in R, here's a minimal explanatory example, using the
pROC
package: