Task API Comparison¶
This page compares the two primary workflows for creating calibrated explanations: the wrapper API (WrapCalibratedExplainer) and the direct API (CalibratedExplainer).
When to use each API¶
Scenario |
Recommended API |
Reason |
|---|---|---|
Quick start with scikit-learn models |
|
Familiar fit/calibrate workflow |
Full control over calibration |
|
Direct access to all parameters |
Preprocessing integration |
|
Built-in preprocessing support |
Advanced customization |
|
Maximum flexibility |
Wrapper API (WrapCalibratedExplainer)¶
The wrapper provides a scikit-learn-style interface:
from calibrated_explanations import WrapCalibratedExplainer
# Initialize
wrapper = WrapCalibratedExplainer(model)
# Fit and calibrate
wrapper.fit(x_train, y_train)
wrapper.calibrate(x_cal, y_cal)
# Generate explanations
factual = wrapper.explain_factual(x_test)
alternatives = wrapper.explore_alternatives(x_test)
Key features:
Automatic mode detection (classification vs regression)
Built-in preprocessing support
Simplified workflow for common tasks
Compatible with scikit-learn pipelines
Direct API (CalibratedExplainer)¶
The direct API offers full control:
from calibrated_explanations import CalibratedExplainer
# Fit model separately
model.fit(x_train, y_train)
# Initialize explainer with explicit mode
explainer = CalibratedExplainer(
model,
x_cal,
y_cal,
mode="classification", # or "regression"
feature_names=feature_names,
categorical_features=categorical_features
)
# Generate explanations
factual = explainer.explain_factual(x_test)
alternatives = explainer.explore_alternatives(x_test)
Key features:
Explicit control over all parameters
Fine-grained calibration customization
Direct access to internal state
Suitable for research and advanced use cases
Common parameters¶
Both APIs support the same explanation parameters:
Parameter |
Description |
Example |
|---|---|---|
|
Threshold for probabilistic regression |
|
|
Uncertainty interval bounds |
|
|
Custom discretization bins |
|
Migration between APIs¶
You can convert between APIs:
# Wrapper wrapping a CalibratedExplainer
wrapper = WrapCalibratedExplainer(existing_explainer)
# Access underlying explainer from wrapper
explainer = wrapper.explainer
See the legacy API contract for the complete stable API surface.