Interview Q&A / Machine Learning

BeginnerIn-depth4 min readUpdated 2 Oct 2026

What are precision, recall and F1 score, and why can accuracy be misleading?

SHORT ANSWER

Precision is how many predicted positives were actually positive. Recall is how many actual positives the model found. F1 is their harmonic mean. On imbalanced data, a model can get high accuracy by always predicting the majority class while missing every case you care about.

Explain it simply

Think of a spam SMS filter on your phone.

  • Precision asks: of all the messages the filter put in the spam folder, how many were really spam? Low precision means your OTPs and bank alerts are getting hidden.
  • Recall asks: of all the spam that arrived, how much did the filter catch? Low recall means lottery scams still reach your inbox.
  • F1 score combines both into one number. It is high only when both precision and recall are high.

Accuracy is just "how many predictions were right overall". It sounds good, but if only 5% of messages are spam, a filter that marks nothing as spam is already 95% accurate and completely useless.

Example

1,000 SMS messages: 50 are spam (positive), 950 are genuine (negative). The model's confusion matrix:

Predicted spamPredicted genuine
Actually spam (50)TP = 40FN = 10
Actually genuine (950)FP = 20TN = 930
  • Accuracy = (TP + TN) / total = (40 + 930) / 1000 = 97.0%
  • Precision = TP / (TP + FP) = 40 / 60 = 66.7%
  • Recall = TP / (TP + FN) = 40 / 50 = 80.0%
  • F1 = 2 × P × R / (P + R) = 2TP / (2TP + FP + FN) = 80 / 110 = 72.7%

Now a "lazy" model that predicts genuine for every message: TP = 0, FN = 50, FP = 0, TN = 950. Its accuracy is 950 / 1000 = 95.0%, only 2 points below our real model, but its recall is 0%. Accuracy hid the failure; recall exposed it.

How it works

  • TP (true positive): spam caught. FP (false positive): genuine message wrongly flagged. FN (false negative): spam missed. TN (true negative): genuine message left alone.
  • Precision cares about FP. Recall cares about FN.
  • Most classifiers output a probability. Raising the threshold (say from 0.5 to 0.8) makes the model flag fewer messages, which usually raises precision and lowers recall. Lowering it does the opposite. This is the precision-recall trade-off.
  • F1 uses the harmonic mean, which is pulled towards the smaller value. A model with precision 100% and recall 2% gets an F1 of about 3.9%, not 51%.

Real-world use

  • Recall matters more when missing a positive is costly: cancer screening, fraud detection, detecting defective parts.
  • Precision matters more when a false alarm is costly: spam filters (hiding a real OTP is bad), recommending a loan rejection, YouTube copyright strikes.
  • For imbalanced problems, teams look at precision-recall curves and PR-AUC rather than accuracy.

Common mistakes

  • Reporting accuracy alone on imbalanced data.
  • Mixing up the formulas. A memory trick: Precision looks at the Predicted positives column; Recall looks at the Real positives row.
  • Treating 0.5 as a fixed threshold. Choose the threshold based on the business cost of FP vs FN.
  • Forgetting that F1 ignores true negatives entirely, which is fine for rare-event problems but not always what you want.

What to say in the interview

"Precision is TP over TP plus FP: of everything I flagged, how much was right. Recall is TP over TP plus FN: of all real positives, how many I caught. F1 is the harmonic mean of the two, so it is only high when both are. Accuracy misleads on imbalanced data: if 5% of messages are spam, predicting 'not spam' every time gives 95% accuracy with zero recall. I choose the metric based on which error costs more, recall for fraud or disease, precision for spam filtering, and I tune the threshold accordingly."

Follow-up questions

  • How does changing the classification threshold affect precision and recall?
  • What is the difference between ROC-AUC and PR-AUC?
  • What is specificity?
  • How would you handle a dataset with 1% positives?

Go deeper

Read these once the basics above feel easy.

For more than two classes, compute precision and recall per class and then average. Macro averaging gives each class equal weight, so rare classes count as much as common ones. Weighted averaging weights by class frequency. Micro averaging pools all TP, FP and FN first; for single-label multi-class problems, micro precision, micro recall and micro F1 all equal accuracy. If you care more about one of precision or recall, the F-beta score generalises F1: beta greater than 1 weights recall more, beta less than 1 weights precision more.

#model-evaluation#classification#metrics#confusion-matrix

Related questions

Practise more Machine Learning questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Machine Learning quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.