Command Palette

Search for a command to run...

Hectal
Phase 9: Evaluation and Testing
LLM Engineering · Exercise 2 of 6 PreviousNext
Intermediate

Precision, recall and F1 for one class

Write precision_recall_f1(gold, pred, label). gold and pred are lists of labels of the same length. Count, for label: true positives (gold and pred both equal label), false positives (pred equals label, gold does not) and false negatives (gold equals label, pred does not).

Return (precision, recall, f1) as three floats, not rounded. When a denominator is 0 the value is 0.0 (no crash).

What Check tests

  1. one hit, one false alarm, one miss
  2. a perfect class
  3. high precision, low recall
  4. a label that never appears gives zeros

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.