PythiloLesson 3 of 12 · progress kept in this browser

Practice in Lab: Treat tied ranking scores explicitly in ROC AUC →

Treat tied ranking scores explicitly in ROC AUC

ROC AUC is the probability that a randomly selected positive example receives a higher score than a negative example, with half credit for a tie. This interpretation yields a small exact reference implementation that is useful for testing a faster ranking implementation.

AUC evaluates ranking, not probability calibration or the cost of one operating threshold. With no positive or no negative examples the pairwise probability is undefined. Returning zero would confuse an impossible evaluation with a perfectly reversed ranking. Report the population and class counts alongside the metric.

positive=[.8,.5]
negative=[.5,.1]
credits=[(p>n)+.5*(p==n) for p in positive for n in negative]
print(sum(credits)/len(credits))
Your task

Implement roc_auc(labels,scores) for equal nonempty lists, binary integer labels and finite scores. Compute exact positive-negative pair credit, half for ties. Reject single-class data.