Accuracy is the simplest classification metric โ the fraction of predictions that were correct overall. It's also, famously, the metric most likely to mislead you when classes are imbalanced.
Formula
Numerical Example
Continuing the spam example from Confusion Matrix (TP=24, TN=63, FP=7, FN=6):
Why Accuracy Can Be Deeply Misleading
Consider a disease that affects only 1% of a population. A classifier that always predicts "no disease," regardless of input, achieves 99% accuracy โ an impressive-sounding number that reflects zero actual diagnostic ability. This is exactly the class-imbalance issue previewed in Bayes' Theorem: accuracy alone doesn't distinguish a genuinely capable model from one that's simply exploiting a skewed class distribution.
Code
from sklearn.metrics import accuracy_score
y_true = [1,1,1,1,1,0,0,0,0,0]
y_pred = [1,1,1,0,0,0,0,1,0,0]
print(accuracy_score(y_true, y_pred)) # 0.7 for this small example
When Accuracy Is a Reasonable Metric
| Situation | Is Accuracy Reasonable? |
|---|---|
| Roughly balanced classes | Yes โ a fairly informative, easy-to-interpret starting point |
| Severely imbalanced classes | No โ precision, recall, F1, or PR-AUC (covered next) give a far more honest picture |
| Costs of false positives and false negatives are very different | No โ accuracy treats every error identically, which rarely matches real-world stakes (see the confusion matrix's medical diagnosis example) |
Common Mistakes
- Reporting accuracy as the sole metric on an imbalanced dataset โ this is one of the most common and consequential mistakes in applied machine learning, capable of making a genuinely useless model look impressive.
- Assuming a high accuracy number automatically implies a good model without checking class balance first โ always check the confusion matrix and class distribution before trusting accuracy alone.
Interview Relevance
Q: "A fraud-detection model achieves 99.5% accuracy on a dataset where only 0.5% of transactions are actually fraudulent. Should you be impressed?" Not necessarily โ a model that always predicts "not fraud" would achieve exactly this accuracy while catching zero actual fraud. This is the classic accuracy-paradox scenario; precision, recall and F1 (or PR-AUC) are needed to understand whether the model is actually detecting fraud, not just exploiting the class imbalance.
Practice Question
Using the confusion matrix from the medical diagnosis practice question in Confusion Matrix, compute the model's accuracy.