Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

balanced_accuracy_score

Computes balanced accuracy for binary or multiclass classification by averaging recall across classes. It is designed to provide a more informative score than ordinary accuracy on imbalanced datasets.

Since
0.20

How it works

The function computes recall separately for every class and averages those recalls, preventing classes with more samples from dominating the result. With adjustment disabled, the score ranges from 0 to 1; enabling adjustment accounts for chance-level performance.

Syntax

balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False)

Parameters

NameTypeDescription
y_truearray-like of shape (n_samples,)True target labels.
y_predarray-like of shape (n_samples,)Estimated target labels returned by a classifier.
sample_weightarray-like of shape (n_samples,), default=NoneSample weights.
adjustedbool, default=FalseWhether to adjust the result for chance.

Returns

float: Balanced accuracy score.

Key points

  • The score averages recall across classes rather than aggregating all observations into one overall accuracy.
  • It supports binary and multiclass classification and is especially useful when class distributions are imbalanced.
  • The adjusted option transforms the score so chance-level predictions receive zero.
  • Even after chance adjustment, perfect predictions retain a score of 1.

Common mistakes

  • Setting adjusted=True changes the interpretation of the score: chance-level performance becomes 0 rather than the unadjusted baseline.
  • The usual 0-to-1 range applies when adjusted is False; adjusted scores can have a different lower bound for multiclass problems.

Example: Calculate balanced accuracy

from sklearn.metrics import balanced_accuracy_score

y_true = [0, 1, 0, 0, 1, 0]
y_pred = [0, 1, 0, 0, 0, 1]

score = balanced_accuracy_score(y_true, y_pred)
print(score)  # 0.625

Computes the class-balanced score for the supplied true and predicted labels.

When to use it

Evaluate imbalanced classifiers

Class distributions are uneven and minority-class performance must matter as much as majority-class performance.

Summarize binary performance

A classifier produces binary labels and both sensitivity and specificity should influence one metric.

Use chance-adjusted scoring

Predictions should be compared against a chance-adjusted baseline.

Interview questions

QWhat does balanced accuracy measure?

It is the average of recall values computed independently for each class. This makes it useful when class frequencies are uneven, because frequent classes do not determine the score by themselves.

Follow-up: How does it differ from ordinary accuracy? Ordinary accuracy weights each sample equally, whereas balanced accuracy gives each class equal influence through per-class recall.

QWhat are the function's main parameters?

The signature is balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False). y_true and y_pred contain the actual and estimated targets, while sample_weight optionally weights samples and adjusted controls chance adjustment.

Follow-up: Why is sample_weight keyword-only? The documented signature places it after *, so callers must name it explicitly, reducing accidental argument misplacement.

QHow should the returned score be interpreted?

With adjusted=False, perfect classification gives 1 and the worst value is 0. With adjusted=True, the score is adjusted for chance so random performance scores 0 while perfect performance remains 1.

Follow-up: What is the adjusted lower bound for n classes? It is 1/(1 - n_classes), so the range can extend below zero for multiclass classification.

  • accuracy_score
  • recall_score
  • precision_score
  • classification_report

Source: balanced_accuracy_score — scikit-learn 1.9.1 documentation. Checked 2026-10-15.