Classification (Binary & Multiclass)¶
Calibrated Explanations wraps standard scikit-learn classifiers to produce uncertainty-aware predictions and explanations.
Classification semantics note¶
Calibration prerequisites: fit on
x_proper, y_properand calibrate on held-outx_cal, y_cal.Mode-specific guarantees: Venn-Abers provides calibrated class probabilities with interval bounds.
Assumptions: calibration and deployment data are exchangeable or distribution-matched.
Explicit non-guarantees: no guarantee under drift or regime shift.
Explanation-envelope limits: rule and feature-level intervals summarize model behavior, not causal effects.
Formal semantics: Calibrated interval semantics.
Supported signatures¶
Method |
Description |
|---|---|
|
Point prediction (class label) |
|
Calibrated probabilities (n_samples, n_classes) |
|
Calibrated probabilities plus uncertainty intervals |
|
Factual explanation (rules + uncertainty) |
|
Alternative explanations (counterfactuals) |
ℹ️ Note:
predict()andpredict_proba()match the scikit-learn API but return calibrated values.
Examples¶
1. Calibrated probabilities with uncertainty¶
# Predict probabilities for the positive class (binary) or all classes (multiclass)
probs, (low, high) = explainer.predict_proba(x_test, uq_interval=True)
print(f"Probability: {probs[0, 1]:.3f} (Interval: {low[0, 1]:.3f} – {high[0, 1]:.3f})")
2. Factual explanation¶
Returns the rules explaining why the model made this prediction, with epistemic and aleatoric explanation envelopes on the feature weights.
explanation = explainer.explain_factual(x_test)
3. Explore alternatives¶
Finds what feature changes would be necessary to flip the prediction or increase confidence.
alternatives = explainer.explore_alternatives(x_test)
Multiclass Semantics: What is Explained¶
For multiclass classification, explanations are generated for the predicted class by default:
Factual explanations: Show why the model predicted the specific class it chose
Alternative explanations: Show what would change the prediction to a different class
Probability intervals: Returned per-class via
predict_proba(x, uq_interval=True)
# Get probabilities for all classes with uncertainty
probs, (low, high) = explainer.predict_proba(x_test, uq_interval=True)
# probs.shape = (n_samples, n_classes)
# Explanation focuses on the argmax class by default
factual = explainer.explain_factual(x_test)
Set multi_labels_enabled=True to generate a true multiclass explanation that returns one explanation per class (all-classes view):
multi_factual = explainer.explain_factual(x_test, multi_labels_enabled=True)
multi_alternative = explainer.explore_alternatives(x_test, multi_labels_enabled=True)
Multi-label mode support matrix (multi_labels_enabled=True)¶
Capability |
Status |
Notes |
|---|---|---|
Per-class factual explanations |
Supported |
Returns one explanation per class for each instance |
Per-class alternative explanations |
Supported |
Same container shape as factual mode |
|
Supported |
Returns calibrated probability intervals per class |
Collection operations ( |
Supported |
Applied across class-specific explanations |
|
Supported |
Reject handling applies in multiclass branch |
|
Supported |
Forwarded in multiclass explain paths |
Narrative/dataframe export |
Supported |
Collection-level multiclass narrative/dataframe output |
JSON export/import |
Supported |
|
Binary datasets with |
Limited |
Allowed with compatibility warning; use default mode when all-classes output is unnecessary |
ℹ️ Note: The rule table shows contributions toward the predicted class. Negative weights reduce confidence in the prediction; positive weights increase it.
Key parameters¶
bins: Supply Mondrian categories/bins for conditional calibration.uq_interval: Set toTrueto receive uncertainty intervals (tuples of lower/upper bounds).
Entry-point tier: Tier 2.