Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-255

Per-Class AP (VOC)

Problem

Compute average precision for one class from score-ordered detections.

labels[k] is 1 for a positive detection and 0 otherwise, already sorted by descending score. For every positive add the precision at that rank (tp / (k + 1)), then divide by the number of positives. Return 0.0 when there are no positives, otherwise round to 4 decimal places.

Hint

Precision at rank k uses only the detections seen so far.

Test cases

case 1
in: [[1,0,1,1,0]]
expected: 0.8056
case 2
in: [[0,1]]
expected: 0.5
case 3
in: [[1,1,0]]
expected: 1
case 4
in: [[0,0]]
expected: 0
Starter codePython
def average_precision(labels):
    # Your code here
    pass

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