Balanced Accuracy Classification Models
When evaluating classification models, choosing the right performance metric is essential. Accuracy can provide a misleading picture when the classes in a dataset are imbalanced. A model may achieve a high overall accuracy simply by predicting the majority class most of the time.
Balanced accuracy addresses this problem by giving equal importance to each class. It is particularly useful when one class is much more common than another, such as fraud detection, disease diagnosis, rare-event prediction, and other classification problems with uneven class distributions.
In this article, we will explain what balanced accuracy is, how it is calculated, why it is useful, and how it compares with conventional accuracy.
What Is Balanced Accuracy?
Balanced accuracy is a classification metric that calculates the average recall obtained across classes.
For a binary classification problem, balanced accuracy is calculated as: Balanced Accuracy=2Sensitivity+Specificity
where:
- Sensitivity measures how well the model identifies positive cases.
- Specificity measures how well the model identifies negative cases.
Unlike conventional accuracy, balanced accuracy gives equal weight to both classes regardless of how frequently they occur.
Understanding the Confusion Matrix
To understand balanced accuracy, it is helpful to first understand the confusion matrix.
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive | TP | FN |
| Actual Negative | FP | TN |
Where:
- TP (True Positive): Positive cases correctly classified.
- TN (True Negative): Negative cases correctly classified.
- FP (False Positive): Negative cases incorrectly classified as positive.
- FN (False Negative): Positive cases incorrectly classified as negative.
These four values are used to calculate several classification metrics.
Sensitivity
Sensitivity is also called True Positive Rate (TPR) or recall for the positive class. Sensitivity=TP+FNTP
It answers:
“Of all the actual positive cases, how many did the model correctly identify?”
A sensitivity of 0.90 means that the model correctly identifies 90% of the actual positive cases.
Specificity
Specificity is also called the True Negative Rate (TNR). Specificity=TN+FPTN
It answers:
“Of all the actual negative cases, how many did the model correctly identify?”
A specificity of 0.90 means that the model correctly identifies 90% of the actual negative cases.
Balanced Accuracy Formula
Once sensitivity and specificity are calculated: Balanced Accuracy=2Sensitivity+Specificity
For multiclass classification, balanced accuracy is generally calculated as the macro-average of recall across all classes: Balanced Accuracy=K1k=1∑KRecallk
where K is the number of classes.
Why Is Balanced Accuracy Useful?
The main advantage of balanced accuracy is that it prevents the majority class from dominating the performance metric.
Consider a dataset containing:
- 380 negative observations
- 20 positive observations
The positive class represents only 5% of the dataset.
Suppose a model predicts every observation as negative.
It would achieve: Accuracy=400380=0.95
So the model has 95% accuracy.
That sounds impressive.
However, the model identifies none of the positive cases.
Its sensitivity is: 200=0
Its specificity is: 380380=1
Therefore: Balanced Accuracy=20+1=0.50
Balanced accuracy correctly reveals that the model is essentially useless for distinguishing the two classes.
Example: Basketball Draft Prediction
Suppose a logistic regression model is used to predict whether college basketball players will be drafted into the NBA.
Out of 400 players:
- 20 were drafted
- 380 were not drafted
The model produces the following confusion matrix:
| Predicted Drafted | Predicted Not Drafted | |
|---|---|---|
| Actual Drafted | 15 | 5 |
| Actual Not Drafted | 5 | 375 |
Therefore:
- TP = 15
- FN = 5
- FP = 5
- TN = 375
Calculate Sensitivity
Sensitivity=15+515=0.75
The model correctly identifies 75% of drafted players.
Calculate Specificity
Specificity=375+5375=0.9868
The model correctly identifies approximately 98.68% of players who were not drafted.
Calculate Balanced Accuracy
Balanced Accuracy=20.75+0.9868 =0.8684
Therefore, the balanced accuracy is approximately: 0.8684
or 86.84%.
Comparing Balanced Accuracy With Overall Accuracy
Now calculate conventional accuracy: Accuracy=TP+TN+FP+FNTP+TN
For this model: Accuracy=40015+375=0.975
Therefore, overall accuracy is: 97.5%
At first glance, 97.5% looks extremely good.
However, remember that simply predicting every player as “not drafted” would already produce: 400380=95%
accuracy.
The improvement in accuracy is therefore relatively small, while balanced accuracy provides a clearer picture of performance across both classes.
Accuracy vs Balanced Accuracy
| Metric | What It Measures | Sensitive to Class Imbalance? |
|---|---|---|
| Accuracy | Overall proportion correctly classified | Yes |
| Sensitivity | Correct identification of positive cases | No |
| Specificity | Correct identification of negative cases | No |
| Balanced Accuracy | Average recall across classes | Much less |
| Precision | Proportion of predicted positives that are correct | Can vary with prevalence |
| F1 Score | Harmonic mean of precision and recall | Focuses on positive class |
Balanced accuracy is therefore particularly useful when the goal is to evaluate performance fairly across classes.
When Should You Use Balanced Accuracy?
Balanced accuracy is especially useful when:
- Classes are substantially imbalanced.
- Both classes are important.
- You want to avoid majority-class dominance.
- The minority class is important.
- You need a single summary metric for class-balanced performance.
Common applications include:
Healthcare
Examples include:
- Disease vs no disease
- Adverse event vs no adverse event
- High-risk vs low-risk patients
A model with 98% accuracy may still be poor if the disease is rare and the model fails to identify affected patients.
Fraud Detection
Fraudulent transactions may represent only a tiny fraction of all transactions.
A model that predicts “not fraud” for almost every transaction could achieve very high accuracy while failing its primary purpose.
Manufacturing
Defective products may be relatively rare compared with non-defective products.
Balanced accuracy can help evaluate whether the model detects defects without being dominated by the large number of acceptable products.
Customer Churn
If only a small percentage of customers churn, a model can achieve high accuracy by predicting that most customers will remain.
Balanced accuracy provides a better view of performance across churners and non-churners.
Balanced Accuracy vs F1 Score
Balanced accuracy and F1 score are related but answer different questions.
Balanced accuracy averages sensitivity and specificity: BA=2Sensitivity+Specificity
F1 score combines precision and recall: F1=2Precision+RecallPrecision×Recall
Balanced accuracy considers both positive and negative classes through sensitivity and specificity.
F1 score focuses primarily on the positive class, using precision and recall.
Therefore, the choice depends on the problem.
If both classes are important, balanced accuracy may be more appropriate.
If the positive class is the primary focus, F1 score may be useful alongside precision and recall.
Balanced Accuracy for Multiclass Classification
Balanced accuracy is not limited to binary classification.
Suppose a model predicts three classes:
- Class A
- Class B
- Class C
Suppose the recall values are:
- Class A = 0.90
- Class B = 0.70
- Class C = 0.80
Then: Balanced Accuracy=30.90+0.70+0.80 =0.80
Therefore, the balanced accuracy is 80%.
This approach prevents a large class from dominating the overall evaluation.
Balanced Accuracy in R
In R, balanced accuracy can be calculated from sensitivity and specificity.
For example:
sensitivity<-0.75specificity<-0.9868balanced_accuracy<- (sensitivity+specificity) /2balanced_accuracy
You can also use packages such as caret for classification performance evaluation.
library(caret)confusionMatrix(predicted,actual,positive="Yes")
The confusion matrix output provides several useful classification metrics.
Balanced Accuracy in Python
Using scikit-learn:
fromsklearn.metricsimportbalanced_accuracy_scorey_true= [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]y_pred= [1, 1, 1, 0, 0, 0, 0, 0, 0, 0]score=balanced_accuracy_score(y_true, y_pred)print("Balanced Accuracy:", score)For model evaluation, balanced accuracy can be incorporated directly into cross-validation and hyperparameter tuning.
Important Limitations
Balanced accuracy is useful, but it should not be treated as the only classification metric.
It Does Not Measure Calibration
A model can have good balanced accuracy while producing poorly calibrated probabilities.
If predicted probabilities are important, also consider:
- Brier score
- Calibration curves
- Expected calibration error
It Does Not Capture Every Error Cost
Balanced accuracy gives equal weight to classes, but real-world applications may have unequal costs.
For example, in a medical screening problem, a false negative may be much more serious than a false positive.
In such cases, metrics should reflect the actual decision consequences.
It Does Not Replace the Confusion Matrix
Always inspect the confusion matrix alongside balanced accuracy.
The confusion matrix shows exactly which types of errors the model makes.
Balanced Accuracy and Threshold Selection
Balanced accuracy can also be useful when selecting a classification threshold.
Many classifiers produce probabilities rather than direct class labels.
For example:
Predicted probability = 0.72
You might classify this observation as positive using a threshold of 0.50.
However, changing the threshold changes:
- Sensitivity
- Specificity
- Precision
- Balanced accuracy
Therefore, for applications where class balance matters, the classification threshold can be selected using validation data rather than automatically using 0.50.
Best Practices for Imbalanced Classification
When dealing with imbalanced datasets, consider evaluating several complementary metrics:
- Balanced accuracy
- Sensitivity/recall
- Specificity
- Precision
- F1 score
- ROC-AUC
- Precision-recall AUC
- Confusion matrix
- Calibration metrics where probabilities matter
The appropriate metric depends on the actual business or scientific objective.
For highly imbalanced problems, precision-recall curves can sometimes provide more useful information about positive-class performance than ROC-AUC alone.
Conclusion
Balanced accuracy is an important classification metric for evaluating models when class distributions are imbalanced.
Unlike conventional accuracy, which can be dominated by the majority class, balanced accuracy gives equal consideration to the performance of each class.
For binary classification: Balanced Accuracy=2Sensitivity+Specificity
In the basketball draft example, the model achieved 97.5% overall accuracy but a balanced accuracy of approximately 86.84%. The difference demonstrates why relying solely on accuracy can be misleading when the target classes are highly imbalanced.
Balanced accuracy should ideally be used alongside the confusion matrix, sensitivity, specificity, precision, F1 score, and appropriate probability-based metrics.
Ultimately, the best classification metric is the one that reflects the real-world objective and the relative consequences of different types of prediction errors.