Precision, Recall and F1 Score, Explained Simply
What precision, recall and F1 score mean, how to calculate them from a confusion matrix, and how to choose which one matters for your problem.
Short answer: precision and recall measure two different kinds of correctness for a model that says "yes" or "no". Precision asks: of everything the model flagged as positive, how much was really positive? Recall asks: of everything that was really positive, how much did the model find? The F1 score combines the two into a single number.
Why Isn't Accuracy Enough?
Imagine a spam filter. If only 1 email in 100 is spam, a "model" that says "not spam" every time is 99% accurate and completely useless. Accuracy hides this because the classes are unbalanced. Precision and recall look at the class you actually care about.
What Is the Confusion Matrix?
Everything starts from four counts, comparing what the model said with what was true:
Model says positive | Model says negative | |
|---|---|---|
Really positive | True positive (TP) | False negative (FN), a miss |
Really negative | False positive (FP), a false alarm | True negative (TN) |
How Do You Calculate Precision and Recall?
Precision = TP / (TP + FP). How trustworthy a "positive" label is.
Recall = TP / (TP + FN). How many real positives were caught.
F1 = 2 × precision × recall / (precision + recall). A harmonic mean, which stays low unless both numbers are reasonably high.
A worked example: a model checks 10 emails. Four are really spam. It flags five emails as spam, and three of those are correct. So TP = 3, FP = 2, FN = 1.
Precision = 3 / (3 + 2) = 0.60
Recall = 3 / (3 + 1) = 0.75
F1 = 2 × 0.60 × 0.75 / (0.60 + 0.75) ≈ 0.67
You can check this with a few lines of Python:
actual = [1, 1, 1, 1, 0, 0, 0, 0, 0, 0] # 1 = spam
predicted = [1, 1, 1, 0, 1, 1, 0, 0, 0, 0]
tp = sum(1 for a, p in zip(actual, predicted) if a == 1 and p == 1)
fp = sum(1 for a, p in zip(actual, predicted) if a == 0 and p == 1)
fn = sum(1 for a, p in zip(actual, predicted) if a == 1 and p == 0)
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1 = 2 * precision * recall / (precision + recall)
print(tp, fp, fn) # 3 2 1
print(round(precision, 2), round(recall, 2), round(f1, 2)) # 0.6 0.75 0.67
In real projects, libraries such as scikit-learn have ready-made functions for these, but writing them once by hand makes the idea stick.
Which Matters More: Precision or Recall?
It depends on which mistake costs more.
Situation | Worse mistake | Favour |
|---|---|---|
Medical screening for a serious illness | Missing a sick person (FN) | Recall |
Marking emails as spam | Hiding a real email (FP) | Precision |
Fraud alerts reviewed by staff | Missing fraud (FN) | Recall |
Automatically banning accounts | Punishing an innocent user (FP) | Precision |
You usually trade one for the other. A model that flags everything has perfect recall and poor precision; a model that flags only the surest case has high precision and poor recall. Changing the decision threshold moves you along this trade-off.
When Is F1 Useful?
Use F1 when you want one number that balances both and your classes are unbalanced. If one error type clearly matters more, report precision and recall separately instead of hiding them in F1. The same idea is used to judge AI and LLM systems, for example how many relevant documents a search step retrieves.
Common Mistakes
Reporting only accuracy on unbalanced data.
Mixing up the formulas. Remember: precision's denominator is everything the model predicted positive; recall's is everything really positive.
Judging on the training data. Measure on data the model has not seen.
Forgetting the cost. The "best" balance is the one that fits the real-world cost of each mistake.
For more practice, see the tutorial Precision, Recall, F1 and the Confusion Matrix, and the earlier post on the types of machine learning.
Key Takeaway
Precision is "how many flagged items were right"; recall is "how many real items did we find"; F1 balances both. Pick the metric that matches the mistake you can least afford.
Ready to start? Learn the maths behind model metrics, probability and statistics in plain steps with Python examples. Begin with the free course Maths and Statistics for AI: The Essentials.
Related articles
More in Machine Learning
Training vs Validation vs Test Data
Why machine learning data is split into training, validation and test sets, what each is for, how to split it and how to avoid data leakage.
3 min readNov 13, 2026Classification vs Regression in Machine Learning
Classification predicts a category and regression predicts a number. See the differences, examples, metrics and a tiny Python demo of both.
4 min readNov 10, 2026Overfitting vs Underfitting, Explained Simply
What overfitting and underfitting mean, how to spot each from training and test error, and how to fix them, with a small runnable example.
4 min readNov 8, 202610 Real-World Uses of Deep Learning
Deep learning powers speech recognition, translation, recommendations, chatbots and more. See 10 real uses and the kind of model behind each.
4 min readNov 5, 2026How Much Maths Do You Need for Machine Learning?
An honest answer by goal: how much linear algebra, probability, statistics and calculus you need for machine learning, what to skip at first, and how to learn it alongside coding.
4 min readNov 3, 2026How Does a Neural Network Work? A Simple Explanation
Neurons, weights, bias, layers and how a network learns from its mistakes, explained in plain words with a handwritten-digit example and no heavy maths.
4 min readOct 30, 2026
Comments
Sign in to join the discussion.

