Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-325

ROC and PR Area Gap

Problem

Return the difference between the trapezoidal PR area and the trapezoidal ROC area for the same curve. Precision at each point is tpr * prevalence / (tpr * prevalence + fpr * (1 - prevalence)), using 1.0 when the denominator is 0, and the PR area integrates precision over recall (tpr). Return pr_auc - roc_auc, or 0.0 when prevalence is not strictly between 0 and 1 or there are fewer than two points.

Hint

PR curves reward early precision and are much more sensitive to class imbalance than ROC curves.

Test cases

case 1
in: [[0,0,1],[0,1,1],0.5]
expected: 0
case 2
in: [[0,0.5,1],[0,0.5,1],0.5]
expected: 0.125
case 3
in: [[0,1],[0,1],0.1]
expected: 0.050000000000000044
case 4
in: [[0,1],[0,1],0]
expected: 0
case 5
in: [[0],[0],0.5]
expected: 0
Starter codePython
def roc_pr_area_gap(fpr, tpr, prevalence):
    # Your code here
    pass

5 test cases · run your code against them in the editor