PIXELBANKv9.1.0
Menu

Precision-Recall Curve Points

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:

Processing detections in order:

  1. Detection 1: True (matched)

    • TP = 1, Total detections = 1
    • Precision = 1/1 = 1.0
    • Recall = 1/3 = 0.3333
  2. Detection 2: False (false positive)

    • TP = 1, Total detections = 2
    • Precision = 1/2 = 0.5
    • Recall = 1/3 = 0.3333 (unchanged)
  3. Detection 3: True (matched)

    • TP = 2, Total detections = 3
    • Precision = 2/3 = 0.6667
    • Recall = 2/3 = 0.6667

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
🔒

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

0/0
Run code to see test results.
Precision-Recall Curve Points - Medium | PixelBank