Accuracy alone is a trap. A model that predicts "not fraud" every single time scores 99.9% on a dataset where fraud is one in a thousand — and is completely useless. The other three metrics are what expose that.
From the four confusion-matrix counts (TP, TN, FP, FN):
| metric | formula | question it answers |
|---|---|---|
| accuracy | (TP + TN) / total | how often am I right? |
| precision | TP / (TP + FP) | when I say yes, am I right? |
| recall | TP / (TP + FN) | of the real positives, how many did I catch? |
| F1 | 2PR / (P + R) | the harmonic mean of the two |
Task: write classification_metrics(y_true, y_pred) for binary labels (1 positive, 0 negative), returning [accuracy, precision, recall, f1], each rounded to 4 decimal places.
0.0.F1 uses the harmonic mean rather than the ordinary one on purpose: it collapses toward whichever of the two is worse. Precision 1.0 with recall 0.01 averages to 0.5 the usual way, but F1 gives about 0.02 — which is a far more honest description of that model.