Machine learning models are only as good as the metrics used to evaluate them. When building a classification model, three evaluation metrics often cause confusion: accuracy, precision, and recall. Although they seem similar, they measure very different aspects of model performance — and choosing the wrong one can lead to dangerously misleading conclusions.

What Are Accuracy, Precision, and Recall?

These are classification evaluation metrics used to measure how well a model performs. Each answers a different question about your model's behaviour.

ACCURACY
Overall correctness

What proportion of all predictions were right?

PRECISION
Positive prediction quality

Of everything flagged positive, how many truly were?

RECALL
Positive capture rate

Of all real positives, how many did the model catch?

All three are calculated from a confusion matrix — the foundation of classification evaluation.

Understanding the Confusion Matrix

A confusion matrix is a 2×2 table that breaks down model predictions into four categories. Every classification metric derives from these four values.

PREDICTED ← what the model said → ACTUAL Predicted Positive Predicted Negative Actual Positive Actual Negative TP True Positive Correctly caught FN False Negative Missed positive FP False Positive False alarm TN True Negative Correctly ignored TP = spam caught correctly  ·  TN = normal email ignored correctly  ·  FP = normal flagged as spam  ·  FN = spam missed
TP — Correctly predicted positive TN — Correctly predicted negative FP — Predicted positive, actually negative FN — Predicted negative, actually positive

All Formulas at a Glance

ACCURACY (TP + TN) ÷ (TP + TN + FP + FN)
PRECISION TP ÷ (TP + FP)
RECALL TP ÷ (TP + FN)
F1 SCORE 2 × (Precision × Recall) ÷ (Precision + Recall)

Accuracy Explained

Accuracy measures the proportion of all correct predictions out of total predictions — both positive and negative.

ACCURACY FORMULA
Accuracy = (TP + TN) ÷ (TP + TN + FP + FN)
TP: correctly caught positives TN: correctly ignored negatives

When Accuracy Works Well

  • Classes are roughly balanced (e.g. 50/50 split)
  • Cost of false positives and false negatives is similar
  • You need a quick, broad overview of model performance

Precision Explained

Precision answers: "Of all the cases my model flagged as positive, how many actually were?" It penalises false alarms.

PRECISION FORMULA
Precision = TP ÷ (TP + FP)
TP: true positives FP: false alarms penalised

When to Use Precision

Use precision when false positives are costly. In fraud detection, wrongly flagging a legitimate transaction creates customer frustration and support overhead. High precision ensures flagged transactions are genuinely suspicious.

// RULE OF THUMB
High precision = fewer false alarms. Every positive flag the model raises is likely to be real.

Recall Explained

Recall answers: "Of all the actual positives that existed, how many did my model catch?" It penalises missed cases.

RECALL FORMULA
Recall = TP ÷ (TP + FN)
TP: true positives FN: missed positives penalised

When to Use Recall

Use recall when false negatives are dangerous. In cancer screening, missing a true positive case is far worse than an unnecessary follow-up test. Maximising recall ensures the model catches as many real cases as possible.

// RULE OF THUMB
High recall = few missed cases. The model casts a wide net to avoid letting real positives slip through.

Worked Example — Spam Detection

Suppose a classifier evaluates 200 emails and produces the following confusion matrix values. Let's calculate all four metrics:

TP = 80  (spam caught) TN = 100  (normal ignored) FP = 10  (normal flagged) FN = 10  (spam missed)
// calculations
Accuracy (80+100) / 200 = 0.90
Precision 80 / (80+10) = 0.89
Recall 80 / (80+10) = 0.89
F1 Score 2×(0.89×0.89)/(0.89+0.89) = 0.89
// interpretation
90% accuracy 9 in 10 predictions correct
89% precision ~1 in 9 flags is a false alarm
89% recall ~1 in 9 spams slips through
F1 = 0.89 Balanced — good overall

// in this balanced example all three metrics agree. The dangerous cases are imbalanced datasets — covered next.

The Accuracy Paradox

In imbalanced datasets, accuracy becomes dangerously misleading. A model can achieve very high accuracy by simply predicting the majority class every time — while completely failing at its actual job.

⚠ ACCURACY PARADOX — Imbalanced Spam Dataset

Dataset: 950 normal emails, 50 spam (95/5 split). Model predicts "not spam" for everything.

95%
Accuracy
0%
Recall
0 / 50
Spam caught
Useless
Model verdict
// KEY INSIGHT
High accuracy on imbalanced data means nothing. A model that predicts the majority class every single time can look excellent by accuracy alone while having zero predictive value for the minority class.

The Precision–Recall Trade-Off

There is an inherent tension between precision and recall. Lowering the classification threshold catches more positives (higher recall) but also more false alarms (lower precision). Raising the threshold reduces false alarms (higher precision) but misses more real positives (lower recall).

1.0 0.5 0.0 Precision / Recall Low Threshold High ← classification threshold → optimal zone Precision Recall F1 Score

// as the threshold rises, precision climbs and recall falls. F1 score peaks where the two balance — the optimal zone.

What Is the F1 Score and Why It Matters

The F1 score is the harmonic mean of precision and recall. It gives a single number that balances both, making it the go-to metric for imbalanced datasets where you care about both false positives and false negatives.

F1 FORMULA
F1 = 2 × (Precision × Recall) ÷ (Precision + Recall)
  • F1 = 1.0 — perfect precision and recall
  • F1 = 0.0 — either precision or recall is zero
  • F1 > 0.7 — generally considered good on imbalanced data
// WHY HARMONIC MEAN
F1 uses the harmonic mean rather than arithmetic mean because it punishes extreme imbalances. A model with precision 1.0 and recall 0.01 has an arithmetic mean of 0.505 but an F1 of only 0.02 — correctly signalling a broken model.

Metrics for Imbalanced Datasets

In fraud detection where only 1% of transactions are fraudulent, a model that predicts "not fraud" for everything achieves 99% accuracy but recall of 0%. The imbalance exposes accuracy as useless.

⚠ Fraud Detection — 99/1 Class Imbalance

Accuracy
99%
0.99
Recall
0 fraud caught
0.00
F1 Score
near zero — model is useless
≈ 0.02
Accuracy hides the complete failure. F1 and recall expose it immediately.
// CHECKLIST FOR IMBALANCED DATA
Always use precision, recall, and F1. Also consider ROC-AUC, PR-AUC, and Matthews Correlation Coefficient (MCC) for a full picture. Never report only accuracy on imbalanced problems.

Which Metric Should You Use?

Always choose your evaluation metric based on the business consequences of each type of error in your specific problem.

📧 Spam Detection PRECISION

Flagging a legitimate email as spam is disruptive. Minimise false positives.

FP cost is high → optimise precision
🏥 Cancer / Disease Detection RECALL

Missing a real case can be fatal. Catch every positive even at the cost of false alarms.

FN cost is critical → optimise recall
💳 Fraud Detection F1 SCORE

Missing fraud (FN) and blocking innocent customers (FP) are both costly. Balance both.

Both errors matter → optimise F1
📊 Balanced Classification ACCURACY

Equal class distribution and equal cost for each error type. Accuracy is reliable here.

Balanced data, equal costs → accuracy is fine
Metric Measures Penalises Best used when
Accuracy Overall correctness All errors equally Balanced classes
Precision Quality of positive flags False positives FP is costly (spam, legal)
Recall Coverage of real positives False negatives FN is dangerous (medical)
F1 Score Harmonic balance Both FP and FN Imbalanced datasets

Python Implementation

Scikit-learn makes computing all four metrics trivial. Here is a complete example on a binary classification problem:

evaluate_metrics.py
from sklearn.metrics import (
    accuracy_score,
    precision_score,
    recall_score,
    f1_score,
    confusion_matrix,
    classification_report
)

# ── Example predictions ──────────────────────────────────
y_true = [1, 0, 1, 1, 0, 1, 0, 0, 1, 1]   # actual labels
y_pred = [1, 0, 1, 0, 0, 1, 1, 0, 1, 0]   # model predictions

# ── Individual metrics ───────────────────────────────────
print(f"Accuracy : {accuracy_score(y_true, y_pred):.4f}")
print(f"Precision: {precision_score(y_true, y_pred):.4f}")
print(f"Recall   : {recall_score(y_true, y_pred):.4f}")
print(f"F1 Score : {f1_score(y_true, y_pred):.4f}")

# ── Confusion matrix ─────────────────────────────────────
cm = confusion_matrix(y_true, y_pred)
print("\nConfusion Matrix:")
print(cm)
# [[TN, FP],
#  [FN, TP]]

# ── Full report (easiest option) ─────────────────────────
print("\nClassification Report:")
print(classification_report(y_true, y_pred))

# ── For imbalanced datasets — adjust averaging ───────────
# zero_division=0 avoids warnings when a class has no predictions
f1_macro  = f1_score(y_true, y_pred, average='macro')
f1_weighted = f1_score(y_true, y_pred, average='weighted')

// use classification_report() as your default — it prints precision, recall, F1, and support for every class in one call.

FAQs

What is the difference between accuracy, precision, and recall?

Accuracy measures overall correctness across all predictions. Precision measures what fraction of positive predictions were actually correct (minimises false alarms). Recall measures what fraction of real positives were caught by the model (minimises missed cases). They serve different business goals.

When should you use precision instead of recall?

Use precision when false positives are costly. In spam detection or fraud alerts, high precision ensures flagged items are genuinely problematic, reducing unnecessary friction for legitimate users.

When is recall more important than precision?

Recall is more important when false negatives are dangerous. In medical diagnosis or safety-critical systems, missing a true positive can have severe consequences, so the model should cast a wide net even at the cost of more false alarms.

Why is accuracy misleading for imbalanced datasets?

With a 99% negative / 1% positive split, a model that always predicts negative achieves 99% accuracy while having zero recall. The majority class dominates the metric, hiding the model's complete failure to detect the minority class.

What is a good F1 score?

It depends on the problem. Generally, F1 > 0.9 is excellent, 0.7–0.9 is good, and 0.5–0.7 is acceptable depending on domain. On highly imbalanced datasets, even F1 > 0.7 can represent strong performance since random guessing would score near zero.

Final Thoughts

Understanding accuracy vs precision vs recall is essential for building reliable machine learning models. Accuracy gives a broad overview, but precision and recall provide deeper insight into where your model fails and why.

  • On balanced datasets with equal error costs — report accuracy
  • When false positives are costly — optimise precision
  • When false negatives are dangerous — optimise recall
  • On imbalanced datasets — always use F1 score (and consider PR-AUC)

Always align your evaluation metric with the real-world consequences of each error type. The best model is not the one with the highest accuracy — it is the one that minimises the errors that matter most to your problem.

Khalid Hussain

Founder of Review Publically. Writes hands-on guides on data science, machine learning and AI tools, testing every model and library before recommending it.