Beyond precision, recall and F1 (already covered in Classification Metrics), two additional metrics — Balanced Accuracy and the Matthews Correlation Coefficient — are specifically built to stay honest on imbalanced data.
Balanced Accuracy
Instead of counting every sample equally (which lets the majority class dominate, exactly like plain accuracy), balanced accuracy averages each class's own recall — treating both classes' performance as equally important, regardless of how many samples each contains.
Worked Example
Confusion matrix: \(TP=30, FN=20\) (50 actual fraud cases), \(FP=50, TN=900\) (950 actual legitimate cases).
Plain accuracy (0.93) looks excellent; balanced accuracy (0.774) tells a much more honest story — the model is only catching 60% of actual fraud, a fact plain accuracy almost completely hides behind the huge, easy-to-get-right majority class.
from sklearn.metrics import balanced_accuracy_score, accuracy_score
y_true = [1]*50 + [0]*950
y_pred = [1]*30 + [0]*20 + [1]*50 + [0]*900
print(accuracy_score(y_true, y_pred)) # 0.93
print(balanced_accuracy_score(y_true, y_pred)) # 0.774
Matthews Correlation Coefficient (MCC)
MCC uses all four confusion matrix cells simultaneously and produces a value between -1 (total disagreement) and +1 (perfect prediction), with 0 meaning no better than random — widely regarded as one of the single most balanced, hard-to-game classification metrics, especially for imbalanced data.
from sklearn.metrics import matthews_corrcoef
print(matthews_corrcoef(y_true, y_pred)) # 0.440
MCC's moderate value (0.44) — neither near 0 (useless) nor near 1 (excellent) — accurately reflects a model that's meaningfully better than chance but still missing a real chunk of the minority class, a more nuanced picture than accuracy's misleadingly high 0.93.
Why These Metrics Resist the Imbalance Trap
| Metric | Why It's Robust to Imbalance |
|---|---|
| Balanced Accuracy | Averages per-class recall — the majority class can't dominate the average just by being larger |
| MCC | Uses all four confusion matrix cells in a single formula — a model that ignores the minority class can't score well, unlike plain accuracy |
Practical Use Cases
- Reporting a single, hard-to-game summary metric for genuinely imbalanced classification problems
- Comparing models fairly when class balance differs across datasets or over time
Common Mistakes
- Still reporting only plain accuracy as the headline number, even after computing these more honest metrics elsewhere in the analysis.
- Interpreting MCC on the same [0,1] scale as accuracy — remember it can be negative, indicating predictions worse than random.
Interview Relevance
Q: "Why is MCC considered more reliable than F1-score for some imbalanced problems?" F1 only combines precision and recall, ignoring the true negative count entirely; MCC incorporates all four confusion matrix values (TP, TN, FP, FN) in one balanced formula, making it harder for a model to score well by exploiting a specific error pattern that F1 alone might not fully penalize.
Practice Question
Given \(TP=8, FN=2, FP=5, TN=85\) (10 actual positives, 90 actual negatives), compute balanced accuracy and compare it to plain accuracy for this confusion matrix.