v9.1.1
Menu

Precision-Recall Curve Points

mediumPROObject DetectionDetectionCV: Recognition

You are given detection results (whether each detection matched a ground truth object) and need to compute precision and recall at each detection to construct a PR curve.

Detections should be processed in order of decreasing confidence (highest first).

For each detection processed:

  • Precision = True Positives / Total Detections So Far
  • Recall = True Positives / Total Ground Truth Objects

Precision=TPTP+FPRecall=TPTP+FN=TPnum_gtPrecision = \frac{TP}{TP + FP} \quad\quad Recall = \frac{TP}{TP + FN} = \frac{TP}{\text{num\_gt}}

Where:

  • TP = detections that matched a ground truth
  • FP = detections that didn't match (false alarms)
  • num_gt = total ground truth objects

Round precision and recall to 4 decimal places.

Example

Input
matches = [True, False, True]
num_gt = 3
Output
[(1.0, 0.3333), (0.5, 0.3333), (0.6667, 0.6667)]
Reasoning
  • Inputs: matches lists the three detections from most to least confident: a hit, a false alarm, then another hit. num_gt = 3 means three real objects exist in the image, whether or not anything found them.
  • After detection 1 (hit): TP =1= 1 out of 11 detection, so precision =11=1.0= \frac{1}{1} = 1.0 and recall =13≈0.3333= \frac{1}{3} \approx 0.3333.
  • After detection 2 (false alarm): TP stays 11, but 22 detections have now been made, so precision falls to 12=0.5\frac{1}{2} = 0.5. Recall is still 13=0.3333\frac{1}{3} = 0.3333, because a false alarm finds no new object.
  • After detection 3 (hit): TP =2= 2 out of 33 detections, so precision =23≈0.6667= \frac{2}{3} \approx 0.6667 and recall =23≈0.6667= \frac{2}{3} \approx 0.6667.
  • Output: one (precision, recall) pair per detection, rounded to 4 decimal places: [(1.0, 0.3333), (0.5, 0.3333), (0.6667, 0.6667)].
  • Notice that recall can only rise or stay flat as you go down the list, while precision can drop and recover. That is why PR curves zigzag. Recall here never reaches 11: one object was never detected.

Constraints

  • matches: list of booleans, True if detection matched ground truth, False otherwise
  • Detections are already sorted by confidence (highest first)
  • num_gt: total number of ground truth objects
  • Return list of (precision, recall) tuples

Learn this in

More from CV: Recognition

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.