Precision and Recall — ML Technical Interview Questions & Answers
Trade-offs between false positives and false negatives.
Precision and Recall
- Simple meaning: Precision = of the students I flagged as fail, how many really failed? Recall = of all real fails, how many did I catch?
- Picture: Disease screen — miss a sick person (low recall) is dangerous, so you accept more false alarms. Spam folder — dumping a real mail (low precision) is painful, so you stay strict.
- F1 is the harmonic mean — one number when both matter. They trade off when you move the probability threshold.
- Trap: quoting precision without saying the class. Trap: “we need both 100%” with no threshold talk.
Technical Interview Tip: Spam: precision. Disease: recall. F1 when you need both.
Code Examples for Precision and Recall
Precision and Recall — working example
tp, fp, fn = 3, 1, 1
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1 = 2 * precision * recall / (precision + recall)
print(round(precision, 3), round(recall, 3), round(f1, 3))
# High precision: few false alarms. High recall: catch most real positives.Precision and Recall — precision = TP/(TP+FP); Recall = TP/(TP+FN); F1 is the harmonic mean of both.
How to Explain Precision and Recall to an Interviewer
Precision in words?
Of predicted positives, how many were right
Recall in words?
Of actual positives, how many we caught