Machine Learning · easy
Asked in Data Scientist interviews, in the Machine Learning round.
Precision = of predicted positives how many correct; recall = of actual positives how many caught.
Precision: of the things you flagged, how many were right. Recall: of the things that were really there, how many you flagged.
The example to carry: a spam filter that quarantines 100 emails, of which 90 are spam. Precision is 90%. If the inbox actually received 300 spam emails that day, recall is 90 out of 300, 30%. The filter is careful and misses a lot.
Raise recall by flagging more aggressively and precision falls, because more of what you flag is legitimate mail. The two move against each other through the threshold, and which one you protect is a product decision:
from sklearn.metrics import precision_score, recall_score
precision_score(y_true, y_pred), recall_score(y_true, y_pred)
F1 is their harmonic mean, useful when you must report one number and have no cost model; F-beta lets you weight recall more (beta 2) or less (beta 0.5). Say plainly that both are computed at a threshold, and that the PR curve shows every threshold at once.