The area under the receiver operating characteristic curve (AUC-ROC) is typically defined in terms of the true positive and false positive rates: it is the area under the curve traced by the true positive rate against the false positive rate as the decision threshold varies. Today I learnt that there exists an equivalent (and simpler) formulation: the fraction of positive-negative pairs that are ranked in the correct order (the score of the positive sample is greater than that of the negative one). Put mathematically, if \(N_+\) and \(N_-\) denote the number of positive and negative samples, and \(s_i\) the score of sample \(i\), we have:
Note: Ties (\(s_i = s_j\)) are usually counted as half-correct (assigned a score of 0.5); with this convention, the formula matches exactly the area under the ROC curve.
This formulation makes it easy to see why two common properties of the metric hold:
This formulation also allows us to compute the AUC analytically in certain cases. For example, consider this exercise:
Assume that we have \(2N\) samples (\(N\) positive and \(N\) negative) that are scored and have an AUC-ROC of \(a\). Assume, moreover, that we have \(M\) negative samples that get scores lower than any of those \(2N\) samples, and \(M\) positive samples that get scores larger than any of those \(2N\) samples. So, sorting the samples by score in increasing order, we have something like:
- - - ... - + - - + + - + ... + + + ← neg →← mixed →← pos →What is the AUC over the entire set of \(2N + 2M\) samples?
We count the positive-negative pairs that are ranked correctly:
Dividing by the total number of pairs, \((N + M)^2\), we obtain:
By making the square in the numerator, we get:
As sanity checks, for \(M = 0\) we recover \(a\), and as \(M \to \infty\) the AUC tends to 1.