The difficulty with ROC curves is to understand what happens when the threshold varies. There is no summing, the curve only depends on how many instances have TP/FP/TN/FN status for every threshold.
A perfect model separates the two classes perfectly, this is why it's impossible to have both FP and FN cases:
- if there are FP cases, then the threshold is too low, so there are no FN cases since the two classes are perfectly separated. The FPR is higher than 0 but the TPR is exactly 1.
- Conversely, if there are FN cases then the threshold is too high and therefore are no FP cases for the same reason. Here the TPR is lower than 1 but the FPR is exactly 0.
Example:
prediction value gold status
1.0 P
0.95 P
0.92 P
0.87 P
0.82 N
0.82 N
0.82 N
0.73 N
0.67 N
0.52 N
In this example, the two classes are perfectly separated, i.e. all the Ps are together at the top and all the Ns are together at the bottom.
- if the threshold is higher than 0.87, then we would have FN cases but no FP case at all. This corresponds to a vertical line from (0,0) to (0,1) on the ROC curve, since FPR is 0.
- if the threshold is lower than 0.82, then we would have FP cases but no FN at all. This corresponds to a horizontal line from (0,1) to (1,1) since TPR is 1.
- if the threshold is between .82 and .87, then TPR=1 and FPR=0, this is the top left corner on the curve.
sklearn
predict
method or a perfect score in terms of log loss or Brier score. (Perhaps I’ll demonstrate in an answer later.) $\endgroup$