Accuracy: When It Works and When It Fails
What you'll learn: You'll understand how to compute accuracy and why it can be dangerously misleading when your dataset has imbalanced classes.
What Is Accuracy?
Accuracy is the simplest classification metric: the percentage of predictions your model got right out of all predictions made.
Accuracy = (Correct Predictions) / (Total Predictions)
Using the confusion matrix values:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
Where TP = True Positives, TN = True Negatives, FP = False Positives, FN = False Negatives.
When Accuracy Works Well
Accuracy is perfectly fine when your classes are balanced—meaning you have roughly equal numbers of examples in each category. If you're classifying 500 cats and 500 dogs, 85% accuracy tells a clear story.
When Accuracy Fails: The Imbalanced Class Problem
Imagine you're detecting a rare disease that affects 1% of patients. You build a lazy model that always predicts "healthy" for everyone.
- Out of 1,000 patients: 10 sick, 990 healthy
- Your "always healthy" model gets 990 correct
- Accuracy = 990/1000 = 99%!
Sounds impressive, right? Wrong. Your model is useless—it never catches a single sick patient (0% recall on the positive class), yet accuracy makes it look great.
The analogy: Imagine a fire alarm that never goes off. In a building where fires are rare (1% of days), it's "accurate" 99% of the time... but completely fails at its actual job.
Key Takeaway
Accuracy works when classes are balanced but becomes dangerously misleading with imbalanced datasets—always check your class distribution before trusting accuracy alone.