All problems
Average Precision
Problem
Compute average precision from precision-recall points.
For each distinct recall value keep the largest precision, then integrate over increasing recall: AP = sum of (recall - prev_recall) * precision. Empty input returns 0.0.
Hint
Collapse duplicate recalls to their best precision, then accumulate precision times the recall increase.
Test cases
case 1
in: [[[1,0.5],[0.5,0.5],[0.6666666666666666,1],[0.5,1]]]
expected: 0.8333333333333333
case 2
in: [[[1,1]]]
expected: 1
case 3
in: [[[0.5,0.5],[0.6666666666666666,0.6666666666666666],[0.75,1]]]
expected: 0.611111111111111
case 4
in: [[]]
expected: 0
Starter codePython
def average_precision(pr_points):
# Your code here
pass4 test cases · run your code against them in the editor