Balanced Accuracy Calculator
Balanced accuracy is the macro-average of per-class recall — the metric that cuts through class imbalance when plain accuracy looks too good. Paste a binary confusion matrix or per-class counts and see balanced accuracy, plain accuracy, and the adjusted (chance-corrected) score side by side. Matches scikit-learn.
How it works
Balanced accuracy answers a single question: on average, across all classes, what share of each class did the model get right? It is defined as the macro-average of recall — you compute recall separately for every class, then take the plain (unweighted) mean. Because every class contributes equally regardless of size, a large easy class can no longer prop up the score.
Binary mode. From the confusion-matrix counts the tool computes two recalls:
- Sensitivity (recall of the positive class, TPR) = TP / (TP + FN)
- Specificity (recall of the negative class, TNR) = TN / (TN + FP)
- Plain accuracy = (TP + TN) / (TP + FP + FN + TN)
- Balanced accuracy = (Sensitivity + Specificity) / 2
Multiclass mode. For each class c with correct_c diagonal predictions out of total_c true samples, recall is correct_c / total_c. Balanced accuracy is (1 / C) · Σ recall_c over the C classes that actually have samples. Any class with no true samples gives an undefined recall and is dropped from the average — this mirrors scikit-learn, which returns NaN for such a class and excludes it with a warning.
Adjusted (chance-corrected) balanced accuracy. A model that guesses at random still scores 1/C on balanced accuracy — 50% for two classes. The adjusted variant removes that floor with (BA − 1/C) / (1 − 1/C), mapping random guessing to 0 and a perfect model to 1. It can dip below 0 for worse-than-random models. Balanced accuracy and its adjusted form are the metric scikit-learn exposes as balanced_accuracy_score(..., adjusted=True).
Every figure is computed in your browser in full float64 precision and shown to two decimals. As a self-check, the binary result is also derived from the direct ½·(sensitivity + specificity) formula and compared against the macro-recall value; the calculator confirms the two agree.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.balanced_accuracy_score (API reference)
- scikit-learn — User Guide: Balanced accuracy score
- Brodersen et al. (2010) — The Balanced Accuracy and Its Posterior Distribution (ICPR)
The formulas on this page were last cross-checked against the scikit-learn documentation and the Brodersen et al. definition on 2026-07-12. The three worked examples reconcile to scikit-learn's output.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.