Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-075

Precision-Recall Curve Points

Problem

Compute precision-recall curve points. For each unique score in descending order, predict positive when score >= threshold and append [precision, recall]; precision is 0.0 when nothing is predicted positive.

If there are no positive labels, recall is 0.0. Empty input returns [].

Hint

For each threshold, precision = TP/(TP+FP) and recall = TP/P over the whole dataset.

Test cases

case 1
in: [[0,0,1,1],[0.1,0.4,0.35,0.8]]
expected: [[1,0.5],[0.5,0.5],[0.6666666666666666,1],[0.5,1]]
case 2
in: [[1,1,0,1],[0.9,0.8,0.7,0.6]]
expected: [[1,0.3333333333333333],[1,0.6666666666666666],[0.6666666666666666,0.6666666666666666],[0.75,1]]
case 3
in: [[1,1],[0.5,0.5]]
expected: [[1,1]]
case 4
in: [[],[]]
expected: []
Starter codePython
def pr_curve_points(y_true, scores):
    # Your code here
    pass

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