Read a confusion matrix before accuracy
Accuracy can hide failures when one class is rare. Count true positives, false positives and false negatives, then compute precision and recall from those counts. F1 combines both and is zero when no true positive exists. An empty denominator needs a deliberate convention; this exercise uses zero instead of raising or returning NaN.
tp, fp, fn = 2, 1, 3
print(2 * tp / (2 * tp + fp + fn))Think before coding
The matrix distinguishes missed positives from false alarms. Computing F1 directly avoids a second zero-denominator case from combining precision and recall. Which metric matters depends on the cost of each error. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write binary_metrics(truth, predicted), equal-length lists of 0/1 labels. Return (precision, recall, f1), with zero for any zero denominator.
The explanation opens here once every check passes.