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.
| Quantity | Formula | Meaning |
|---|---|---|
| True positive rate | TP / (TP + FN) | Share of actual positives found |
| True negative rate | TN / (TN + FP) | Share of actual negatives correctly rejected |
| Balanced accuracy | (TPR + TNR) / 2 | Mean recall over both classes |
| Plain accuracy | (TP + TN) / total | Share of all predictions that are correct |
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.
| Classifier | TPR | TNR | Accuracy | Balanced accuracy |
|---|---|---|---|---|
| Always negative | 0.00 | 1.00 | 0.95 | 0.50 |
| Cautious model | 0.40 | 0.99 | 0.96 | 0.70 |
| Sensitive model | 0.90 | 0.90 | 0.90 | 0.90 |
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 compared with related metrics
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.
| Metric | What it emphasizes | Sensitive to class prior | Typical use |
|---|---|---|---|
| Balanced accuracy | Mean recall per class | No | Fair summary across classes |
| Accuracy | Overall correct share | Yes | Balanced classes only |
| F1 score | Precision and recall of positives | Yes | Retrieval and rare-event detection |
| Matthews correlation coefficient | Correlation of all four cells | Partly | Single robust binary summary |
| AUC | Ranking quality over thresholds | No | Threshold-free comparison |
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.
| Situation | Recommended metric | Reason |
|---|---|---|
| Classes roughly equal in size | Accuracy or balanced accuracy | Both give nearly the same value |
| Rare class is critical, false alarms are cheap | Balanced accuracy | Rewards finding the rare class |
| False positives are costly | Precision, F1 score | Balanced accuracy hides false alarms |
| Threshold not yet fixed | AUC or precision-recall curve | Evaluates all operating points |
| Many classes with skewed support | Balanced accuracy plus per-class recall | Prevents large classes from dominating |
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.