Accuracy is the fraction of predictions a classifier gets right: correct answers divided by all answers. If a spam filter labels 1,000 emails and 950 of the labels are correct, its accuracy is 95%. It’s the first number most people reach for, because it needs no explanation.
Reading it off the matrix
For a yes/no classifier, every prediction lands in one of four cells of a confusion matrix: true positives (TP), true negatives (TN), false positives (FP) and false negatives (FN). Accuracy adds up the two correct cells and divides by everything:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
The diagram shows why that is both its strength and its weakness. Accuracy uses the whole matrix but collapses it into one number, and the two kinds of mistake count the same: a false alarm and a missed case each cost one point. Precision and recall each look at only part of the matrix, which is exactly what lets them notice when one kind of error dominates.
The imbalance trap
Accuracy breaks down when classes are uneven. Google’s Machine Learning Crash Course gives the standard example: if the positive class shows up 1% of the time, a model that always predicts “negative” scores 99% accuracy while catching nothing. Fraud detection, disease screening and defect detection all look like this. On an imbalanced dataset, a high accuracy can simply mean the model learned the base rate.
The usual fix is to report metrics that track each class directly:
- Precision and recall, or their harmonic mean, the F1 score.
- Balanced accuracy, the average of the recall on each class. A majority-class guesser drops to 50% on a two-class problem instead of 99%.
- The full confusion matrix, whenever someone has to decide which mistake costs more.
When it’s the right number
Accuracy is fine when classes are roughly balanced and the two kinds of error cost about the same. It also extends naturally to many classes, as the share of examples whose predicted label matches the true one, which is how image-classification benchmarks usually report it. Whatever the setting, compare it with a baseline first: the accuracy you’d get by always predicting the most common class. A number only means something next to that.