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
- one hit, one false alarm, one miss
- a perfect class
- high precision, low recall
- 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.