Accuracy is the simplest classification metric — the fraction of predictions that were correct overall — and also the most commonly misused, since it can look excellent while a model completely fails at the one thing that actually matters.
Formula
Worked Example
Using the confusion matrix from Confusion Matrix: \(TP=15, TN=70, FP=10, FN=5\).
from sklearn.metrics import accuracy_score
y_true = [1]*20 + [0]*80
y_pred = [1]*15 + [0]*5 + [1]*10 + [0]*70
print(accuracy_score(y_true, y_pred)) # 0.85
Why Accuracy Can Be Dangerously Misleading
Imagine a fraud dataset where only 1% of transactions are actually fraudulent. A model that always predicts "not fraud," never catching a single real case, still achieves 99% accuracy — a number that looks excellent while the model is completely useless for its actual purpose. This is exactly why accuracy is a poor default choice on imbalanced data.
from sklearn.metrics import accuracy_score
# 99 legitimate, 1 fraudulent -- model predicts "not fraud" for everyone
y_true = [0]*99 + [1]
y_pred = [0]*100
print(accuracy_score(y_true, y_pred)) # 0.99 -- looks great, catches ZERO fraud
When Accuracy Is Actually a Reasonable Choice
- Roughly balanced classes, where no single class dominates
- Both error types (false positives and false negatives) are similarly costly
- A simple, quick sanity check alongside — never instead of — more nuanced metrics
Practical Use Cases
- Balanced classification problems as a first-pass, easy-to-communicate summary
- Multi-class problems with roughly even class sizes
Common Mistakes
- Using accuracy as the primary or only metric on an imbalanced dataset — the single most common evaluation mistake in classification.
- Reporting accuracy without ever checking the underlying confusion matrix or class distribution first.
Interview Relevance
Q: "A model achieves 99% accuracy on a fraud detection task. Is that good?" Not necessarily — check the class balance first; if fraud is rare (say 1%), a model that never predicts fraud at all would already hit 99% accuracy while being completely useless. Precision, recall and F1 tell a much more honest story on imbalanced problems.
Practice Question
Given \(TP=8, TN=180, FP=2, FN=10\), compute accuracy by hand, then explain why this number alone doesn't tell you how well the model catches the positive class.