Balanced accuracy

On this page 7

Balanced accuracy is a classification metric defined as the arithmetic mean of recall computed separately for each class. For a binary problem it equals the average of sensitivity and specificity. In Model evaluation within Artificial intelligence, it is the standard correction for the main weakness of plain accuracy: misleadingly high scores on imbalanced data.

Because every class contributes equally regardless of its size, a classifier cannot reach a high balanced accuracy simply by predicting the majority class. A model that always answers “negative” on a dataset with 99% negatives scores 99% accuracy but only 50% balanced accuracy, which exposes it as no better than chance.

How balanced accuracy is calculated

Balanced accuracy is calculated from the confusion matrix by dividing correct predictions for each class by the number of true examples of that class, then averaging these per-class recalls. For binary classification the formula is BA = (TPR + TNR) / 2, where TPR is the true positive rate and TNR is the true negative rate.

For K classes the formula generalizes to BA = (1/K) × Σ recall_k, which is identical to macro-averaged recall. The table below shows the quantities involved in the binary case.

QuantityFormulaMeaning
True positive rateTP / (TP + FN)Share of actual positives found
True negative rateTN / (TN + FP)Share of actual negatives correctly rejected
Balanced accuracy(TPR + TNR) / 2Mean recall over both classes
Plain accuracy(TP + TN) / totalShare of all predictions that are correct
Components of binary balanced accuracy

The metric ranges from 0 to 1. A random or constant classifier scores about 1/K in expectation, so 0.5 for binary tasks, which gives balanced accuracy an intuitive chance baseline that plain accuracy lacks. Some libraries offer an adjusted variant that rescales the score so chance equals 0 and perfect prediction equals 1.

Why plain accuracy fails on imbalanced data

Plain accuracy fails on imbalanced data because it weights each example equally, so the majority class dominates the score. Balanced accuracy instead weights each class equally, which is equivalent to reweighting examples by the inverse of their class frequency.

The following table compares both metrics for three classifiers on a test set with 950 negatives and 50 positives.

ClassifierTPRTNRAccuracyBalanced accuracy
Always negative0.001.000.950.50
Cautious model0.400.990.960.70
Sensitive model0.900.900.900.90
Accuracy and balanced accuracy on a 95:5 test set

By plain accuracy the cautious model looks best, yet it misses 60% of positives. Balanced accuracy ranks the sensitive model first, which matches the priority in most screening, fraud and fault detection tasks where the rare class is the one that matters.

Balanced accuracy belongs to a family of metrics designed for imbalanced classification, and each one answers a slightly different question. Choosing among them depends on whether false positives, false negatives or the overall ranking matter most.

MetricWhat it emphasizesSensitive to class priorTypical use
Balanced accuracyMean recall per classNoFair summary across classes
AccuracyOverall correct shareYesBalanced classes only
F1 scorePrecision and recall of positivesYesRetrieval and rare-event detection
Matthews correlation coefficientCorrelation of all four cellsPartlySingle robust binary summary
AUCRanking quality over thresholdsNoThreshold-free comparison
Balanced accuracy and neighboring metrics

A key distinction is that balanced accuracy ignores precision. A model can achieve a high score while producing many false positives on the rare class, because false positives only reduce specificity, which is diluted by the large negative class. When the cost of false alarms is significant, balanced accuracy should be reported alongside precision or the F1 score.

When to use balanced accuracy

Balanced accuracy is the right choice when every class matters equally and the test set does not reflect the importance of each class. It is common in medical diagnosis, intrusion detection, multi-class benchmarks with skewed labels and competitions that need a single comparable number.

SituationRecommended metricReason
Classes roughly equal in sizeAccuracy or balanced accuracyBoth give nearly the same value
Rare class is critical, false alarms are cheapBalanced accuracyRewards finding the rare class
False positives are costlyPrecision, F1 scoreBalanced accuracy hides false alarms
Threshold not yet fixedAUC or precision-recall curveEvaluates all operating points
Many classes with skewed supportBalanced accuracy plus per-class recallPrevents large classes from dominating
Decision guide for reporting balanced accuracy

Balanced accuracy is computed at a fixed decision threshold. Moving the threshold trades sensitivity against specificity, so reported values are only comparable when the threshold policy is stated.

Limitations and common mistakes

Balanced accuracy is robust to class imbalance but not to every evaluation pitfall. The most frequent problems concern interpretation and reporting, not calculation.

  • Treating it as a cost model: equal class weights may not match real costs, which can differ by orders of magnitude.
  • Overlooking unstable recall: with very few examples of a class, its recall and therefore the average have high variance.
  • Confusing it with micro-averaged recall: micro averaging reproduces plain accuracy in single-label tasks.
  • Omitting the chance baseline: a score of 0.6 sounds acceptable but is only modestly above 0.5 for binary tasks.
  • Reporting it alone: a single number hides which class is failing, so per-class recall should accompany it.

When the test set is small, a confidence interval from bootstrapping gives a more honest picture than a single point estimate, especially under distribution shift.

A plain-language summary

Imagine grading a guard dog that must bark at intruders and stay quiet for family members. If intruders are rare, a dog that never barks is “right” almost every time, but it is useless.

Balanced accuracy grades the dog separately on each job and then averages the two grades. The silent dog gets full marks for staying quiet and zero for catching intruders, so its overall grade is only 50%. The score rewards doing well on every group, not just the biggest one.

An example from practice

A hospital analytics team builds a model to flag patients at risk of sepsis from routine vital signs. In the validation set of 10,000 admissions, only 300 patients develop sepsis, a prevalence of 3%.

The first model reports 97.4% accuracy, which initially impresses clinicians. The team then computes per-class recall: specificity is 0.995 but sensitivity is only 0.31, giving a balanced accuracy of about 0.65. The model misses more than two thirds of septic patients.

After reweighting the training loss by class and lowering the decision threshold, a revised model reaches sensitivity of 0.82 and specificity of 0.88. Plain accuracy drops to about 88%, yet balanced accuracy rises to 0.85. The team adds precision to its report so that clinicians also see how many alerts will be false alarms.