Balanced Coverage: Fair Visualization for Imbalanced Data
This example demonstrates plot_balanced_conformal_coverage, which provides a class-balanced view of conformal prediction performance. This is especially useful when dealing with imbalanced datasets.
Key difference from plot_conformal_coverage_by_class:
Each class contributes exactly 50% to the visualization
Coverage is computed as the average of per-class coverages
Prevents the majority class from dominating the visual representation
When to use this plot:
Your dataset has significant class imbalance
You want to ensure fair representation of minority class performance
You need to compare conformal prediction across classes on equal footing
Setup: Creating an Imbalanced Dataset
We’ll use the breast cancer dataset but subsample to create imbalance.
(<Figure size 960x672 with 1 Axes>,
<Axes: title={'center': 'Balanced Coverage by Class'}, xlabel='Confidence Level (1 - α)', ylabel='Class-balanced proportion'>)
Interpretation
Compare the two plots above:
Standard plot: Class 0 (majority) takes most of the visual space. Hard to see how class 1 (minority) is performing.
Balanced plot: Both classes get equal representation (50% each). The balanced coverage line shows the average per-class coverage, giving equal weight to both classes regardless of their frequency.
The balanced view is particularly important when:
Minority class errors are costly (e.g., medical diagnosis)
You need to ensure the model doesn’t sacrifice minority class coverage
Stakeholders need to understand performance on all classes fairly
Mondrian with Balanced Visualization
Combining Mondrian conformal prediction with balanced visualization provides the fairest assessment for imbalanced problems.