Misconception · Statistics Library

Misconception: high accuracy means a sound classifier, even when the classes are imbalanced

When one class is much more common than the others, accuracy can be high for a model that has learned nothing, because always predicting the common class scores that class's share; judge a classifier against that majority-class baseline and by how it does on each class.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

Accuracy is the share of rows a classifier gets right. It sounds like the obvious score, but it misleads under class imbalance, when one class is much more common than the others; data like this are said to have imbalanced classes.

Suppose 980 of 1,000 card transactions are genuine and 20 are fraud. A "model" that calls every transaction genuine is right 980 times out of 1,000: 98% accuracy, while catching no fraud at all. That 98% is the majority-class baseline, the accuracy you get for free by always guessing the most common class. Any accuracy has to be compared with it, not with 50% or with 100%.

A useful model can even have lower accuracy than the baseline. Say a model flags 42 transactions, 12 of them real fraud: it catches 12 of the 20 frauds and wrongly flags 30 genuine ones. Its accuracy is (12 + 950) ÷ 1,000 = 96.2%, below the baseline's 98%, yet it is the only one of the two that finds any fraud.

So look at how the model does on each class, which accuracy hides. The confusion matrix counts, for each actual class, how many rows were predicted as each class. From it come recall (the share of a class's real cases the model catches: 12 of 20, or 60%, for fraud), precision (the share of the model's predictions of a class that are right: 12 of 42, or 29%) and the F1 score, which combines the two. Balanced accuracy averages the recall of every class: for the fraud model it is (60% + 96.9%) ÷ 2 ≈ 78.5%, while always guessing genuine scores only 50%. When the model gives probabilities, ROC-AUC measures how well it ranks the rare cases above the common ones across every cut-off.

This trap is sometimes called the accuracy paradox.

Practitioner explanation

Accuracy = (TP + TN)/n weights each class by its prevalence: with class shares π_k it equals Σ_k π_k · recall_k, so under imbalance it is essentially the majority class's recall. The no-information rate max_k π_k is the floor, and a one-sided binomial test of accuracy against it is a common check. Summaries that do not reward the majority class include balanced accuracy (the mean of the per-class recalls, which does not depend on prevalence) and, with care, macro-averaged F1 and Cohen's kappa, both of which still move with prevalence, through precision and through the chance-agreement term, and for probabilistic models ROC-AUC (threshold-free and invariant to prevalence), with precision-recall curves preferred when the positive class is rare and precision matters. Recall and specificity do not depend on prevalence; precision and F1 do.

Imbalance is a problem of the metric and the decision threshold more than of the model: a well-calibrated probability model can be useful under imbalance while its accuracy at a 0.5 cut-off looks unimpressive, and the right threshold depends on what each kind of error costs. Resampling and class weights change the decision rule (and distort predicted probabilities), not the information in the data; report what they do to recall and precision, measured out of sample Cross-validation. Accuracy measured on the training rows adds a second optimism on top Misconception: a model's training-set accuracy is its real-world performance.

In KernelStats the machine-learning classifier cards (decision tree, random forest, gradient boosting, k-NN, SVM and neural network) use stratified cross-validation and build their confusion matrix from pooled cross-validated predictions; the random forest card adds a per-class precision, recall and F1 table and a Class balance row that warns when the smallest class holds under 10% of rows. The LDA and QDA cards show a Baseline tile ("always predict the majority class") and the naive Bayes card a No-information rate tile; the logistic regression card reports accuracy at the 0.5 cut-off with its confusion matrix and ROC-AUC, and its Class balance row warns when the positive class is under 10% or over 90% of rows. On penguins, the random forest of species on bill length and bill depth reaches 95.9% cross-validated accuracy against a majority-class baseline of 151/342 = 44.2% (Adelie), and its cross-validated confusion matrix shows Chinstrap, the smallest class, with recall 63/68 = 0.926 and precision 63/72 = 0.875.

Worked example

Scenario

1,000 card transactions, 20 of them fraud (2%). Model A calls every transaction genuine; model B flags 42 transactions, 12 of them fraud.

Result

Model A: accuracy 98.0%, fraud recall 0 of 20, balanced accuracy 50%. Model B: accuracy (12 + 950)/1,000 = 96.2%, fraud recall 12/20 = 60%, fraud precision 12/42 = 29%, balanced accuracy (60% + 96.9%)/2 = 78.5%.

Interpretation

Model B is less accurate than doing nothing and far more useful: it catches 60% of the fraud at the cost of 30 false alarms. Whether that trade is worth making depends on what a missed fraud and a false alarm each cost, which accuracy alone cannot show.

Common misconceptions

Misconception

High accuracy means the classifier is good, even when one class is much more common than the others.

Correction

Not when one class dominates: if 98% of the rows belong to one class, a model that always predicts that class scores 98% while never finding a case of the other. Compare accuracy with the majority-class baseline, the share of the largest class, and check each class's recall in the confusion matrix.

Misconception

High accuracy shows the model finds the rare class well.

Correction

Accuracy pools every row, so the common class dominates it, and a model can miss most of the rare class and still score highly. The rare class's recall (the share of its real cases the model catches) and precision (the share of its predicted cases that are right) show how the model does on it.

References

  1. An Introduction to Statistical Learning, 2nd edition, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021), Chapter 4 (the Default data: the null classifier and the confusion matrix).
  2. Applied Predictive Modeling, Kuhn, M. and Johnson, K. (2013), Chapter 11 (measuring performance in classification models) and Chapter 16 (remedies for severe class imbalance).
  3. KernelStats classifier cards (engine code), KernelStats documentation (2026).