Precision and Recall
Precision and recall are two metrics for evaluating classification, especially on imbalanced data. Precision asks 'of the items we flagged, how many were right?' and recall asks 'of all the real positives, how many did we catch?'
Data & AI
Precision = true positives / (true positives + false positives). Recall = true positives / (true positives + false negatives). There's usually a tradeoff: being stricter raises precision but lowers recall, and vice versa.
For a spam filter, high precision means few good emails wrongly flagged; high recall means little spam slips through. The F1 score combines both into a single number. Which matters more depends on the cost of each kind of mistake.
Examples
Python
from sklearn.metrics import precision_score, recall_score
y_true = [1, 1, 0, 1, 0]
y_pred = [1, 0, 0, 1, 1]
print("precision:", round(precision_score(y_true, y_pred), 2))
print("recall: ", round(recall_score(y_true, y_pred), 2))Output:
precision: 0.67
recall: 0.67