Score a classifier and decide between precision-heavy (do not bother users with false alarms) and recall-heavy (do not miss anything) workloads.
Fishing with a net. Precision is how much of what you caught IS fish; recall is how many fish in the lake you actually caught; F1 is the harmony of the two.
TP=10 FP=2 FN=5
precision = 10/12 = 0.83
recall = 10/15 = 0.67
F1 = 2*P*R/(P+R) = 0.74
rare-class -> F1 preferred, accuracy lies
spam -> push precision higher
medical -> push recall higher
Precision is TP divided by TP plus FP. Recall is TP divided by TP plus FN. F1 is the harmonic mean — high only when both are high. Accuracy is right divided by total — useful on balanced data, misleading on imbalanced. For multi-class pass average=macro for per-class balance or average=weighted for class-frequency balance. F-beta generalises F1 with beta controlling precision-vs-recall bias.
from sklearn.metrics import precision_score, recall_score, f1_score
y_true = [0, 1, 1, 1, 0, 1]
y_pred = [0, 1, 0, 1, 0, 1]
print('P:', precision_score(y_true, y_pred))
print('R:', recall_score(y_true, y_pred))
print('F1:', f1_score(y_true, y_pred))
Default binary metrics show only the positive class.
from sklearn.metrics import classification_report
y_true = [0, 1, 2, 2, 0, 1]
y_pred = [0, 1, 2, 0, 0, 2]
print(classification_report(y_true, y_pred, digits=3))
classification_report prints per-class precision/recall/F1 plus macro and weighted averages.
from sklearn.metrics import fbeta_score
print('F2 (recall-heavy):', fbeta_score(y_true, y_pred, beta=2))
print('F0.5 (prec-heavy):', fbeta_score(y_true, y_pred, beta=0.5))
F-beta(2) prioritizes recall by 4x; F-beta(0.5) prioritizes precision by 4x.
Reporting accuracy on rare-event data. A 99 percent accurate fraud model is just one that says no fraud to every transaction. Switch to PR-AUC and F1.
Use precision plus recall plus F1 together. Pick the F-beta that matches your cost: medical uses F2, spam uses F0.5.