induwara.lk
induwara.lkMachine learning · Metrics

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.

By Induwara AshinsanaUpdated Jul 12, 2026
Balanced accuracy
scikit-learn verified

positives predicted positive

positives predicted negative

negatives predicted positive

negatives predicted negative

Sample scenarios
Balanced accuracy
87.11%
macro-average recall
Plain accuracy
84.50%
overall correct ÷ total
Adjusted (chance-corrected)
0.7421
random = 0, perfect = 1
Sensitivity · Specificity
90.00% · 84.21%
the two recalls being averaged
Balanced accuracy
87.11%
Plain accuracy
84.50%
Adjusted
0.7421

Per-class recall

ClassCorrectTotalRecall
Positive455090%
Negative80095084.21%
Balanced accuracy (macro-average recall)87.11%
Balanced accuracy = 87.11% (plain accuracy = 84.50%, adjusted = 0.7421)

Cross-checked: the macro-recall result matches the textbook ½·(sensitivity + specificity) formula to float precision.

Sources: scikit-learn balanced_accuracy_score and Brodersen et al. (2010). All maths runs in your browser — nothing is uploaded.

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

Binary — severe imbalance (disease screening)

TP=10, FN=10, FP=20, TN=960

  1. Sensitivity = TP / (TP + FN) = 10 / 20 = 0.5000
  2. Specificity = TN / (TN + FP) = 960 / 980 = 0.9796
  3. Plain accuracy = (10 + 960) / 1000 = 0.9700 → 97.00%
  4. Balanced accuracy = (0.5000 + 0.9796) / 2 = 0.7398 → 73.98%
  5. Adjusted = (0.7398 − 0.5) / (1 − 0.5) = 0.4796
  6. The 97% headline hides that only half the positives are caught.

Multiclass — 3 classes

A = 27/30, B = 40/50, C = 10/20

  1. Recall A = 27 / 30 = 0.9000
  2. Recall B = 40 / 50 = 0.8000
  3. Recall C = 10 / 20 = 0.5000
  4. Balanced accuracy = (0.9 + 0.8 + 0.5) / 3 = 0.7333 → 73.33%
  5. Plain accuracy = (27 + 40 + 10) / 100 = 0.7700 → 77.00%
  6. Adjusted = (0.7333 − 1/3) / (1 − 1/3) = 0.6000

Balanced binary sanity check

TP=90, FN=10, FP=10, TN=90

  1. Sensitivity = 90 / 100 = 0.9000
  2. Specificity = 90 / 100 = 0.9000
  3. Balanced accuracy = (0.9 + 0.9) / 2 = 0.9000 → 90.00%
  4. Plain accuracy = (90 + 90) / 200 = 0.9000 → 90.00%
  5. With equal-sized classes, balanced accuracy equals plain accuracy.

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.