Agree, this "shouldn't" happen in practice at all and what happens in this case can be undefined. I think of the ROC curve as going from (0,0) to (0,1) in this case since false positive rate (x-axis) is always 0. But *shrug* I could also see wanting to define it as 1 because any classifier is trivially perfect by choosing the minimum threshold, which seems "good".

@schmit hope you don’t mind if I try an explanation.

Here’s a standard reference for the formula: http://cs.ru.nl/~tomh/onderwijs/dm/dm_files/roc_auc.pdf

m and n are the number of positive and negative observations. It’s easy to see that the `/ (nPos * (nObs - nPos))` in the denominator corresponds to this.

To match the summation to the numerator, say the ranks of positive observation i is p_i for i from 1 to m.

Ideally p_i = i for all positive observations — perfect classifier that ranks all positive observations first. But we usually have pi > i.

Positive observation i ranks above all n negative observations, except the ones above it. The number that ranked above must be pi - i. This is the value of the inner summation — over all negative observations — for one positive observation.

Summing p_i - i over all i from 1 to m is just the sum of positive ranks, minus sum of integers 1 to m. And that’s exactly the numerator.