Feature-Conditioned Outcome Distributions (FCODs)
FCODs are an original contribution of conformalpy. They show how prediction outcomes (SC, SI, MC, MU, etc.) vary as a function of input features, revealing where a model is confident, uncertain, or prone to failure.
Unlike Partial Dependence Plots (PDPs) that show how predictions change with features, FCODs show how conformal outcomes change — making them directly actionable for operational decision-making.
Outcome Keys
FCODs use the outcome categories from outcomes:
Binary (K=2): SC, SI, TS0, TS1
Multiclass (K>2): SC, SI, MC, MU
Merging Binary Uncertain Outcomes
In binary classification, TS0 and TS1 split the two-set outcome by true label (TS0 = two-set where true label is 0, TS1 = where true label is 1). At decision time the true label is unknown, so this split has no operational value. Use merge_uncertain_outcomes to collapse them into a single TS before plotting:
from conformalpy.fcod import merge_uncertain_outcomes
# fcod has TS0 and TS1 keys
fcod_merged = merge_uncertain_outcomes(fcod)
# fcod_merged now has a single TS = TS0 + TS1The function is non-destructive (returns a copy) and idempotent — safe to call on results that are already merged or on multiclass results (no-op in both cases). CI bounds (TS0_lower/TS1_lower → TS_lower, etc.) are merged automatically when present.
Prerequisites
All FCOD functions require the prediction sets and true labels from a conformal classifier evaluated on a test set:
# Assuming conf_clf is a calibrated ConformalClassifier
prediction_sets = conf_clf.predict(X_test) # list of sets
# y_test is the array of true labels for the test setComputing FCODs
The simplest way to compute an FCOD is with compute_fcod, which bins a feature and calculates outcome proportions per bin:
from conformalpy.fcod import compute_fcod
fcod = compute_fcod(
feature_values=X_test[:, 0],
prediction_sets=prediction_sets,
y_true=y_test,
n_grid=10,
)
# Returns a dict mapping outcome keys to arrays of proportions per binFor smoother curves, use kernel-smoothed FCODs:
from conformalpy.fcod import compute_fcod_smoothed
fcod_smooth = compute_fcod_smoothed(
feature_values=X_test[:, 0],
prediction_sets=prediction_sets,
y_true=y_test,
n_grid=100,
)Confidence Intervals
FCODs support both bootstrap and pointwise binomial confidence intervals:
from conformalpy.fcod import compute_fcod_with_ci, bootstrap_fcod_ci
# Bootstrap CI
fcod_ci = compute_fcod_with_ci(
feature_values=X_test[:, 0],
prediction_sets=prediction_sets,
y_true=y_test,
n_bootstrap=1000,
)
# Pointwise binomial CI
from conformalpy.fcod import pointwise_binomial_ci
ci = pointwise_binomial_ci(counts, totals, alpha=0.05)Multi-Feature Analysis
Compute FCODs for multiple features at once:
from conformalpy.fcod import compute_multi_feature_fcod
multi_fcod = compute_multi_feature_fcod(
X=X_test,
feature_names=feature_names,
prediction_sets=prediction_sets,
y_true=y_test,
n_grid=10,
)For interaction effects between two features:
from conformalpy.fcod import compute_interaction_fcod
interaction = compute_interaction_fcod(
feature1_values=X_test[:, 0],
feature2_values=X_test[:, 1],
prediction_sets=prediction_sets,
y_true=y_test,
n_grid1=5,
n_grid2=5,
)Visualization
conformalpy provides several plotting functions for FCODs:
from conformalpy.fcod import plot_fcod, plot_stacked_fcod
# Line plot showing outcome proportions vs feature
plot_fcod(fcod, xlabel="income")
# Stacked area plot
plot_stacked_fcod(fcod, xlabel="income")For comparing models side by side:
from conformalpy.fcod import plot_model_comparison_fcod
plot_model_comparison_fcod(
fcod_results={"RF": fcod_rf, "XGB": fcod_xgb},
outcome="SC",
xlabel="income",
)Multi-feature grid and interaction plots:
from conformalpy.fcod import plot_multi_feature_fcod, plot_interaction_fcod
plot_multi_feature_fcod(multi_fcod)
plot_interaction_fcod(interaction, xlabel="income", ylabel="age")Uncertainty zone visualization highlights regions of high uncertainty:
from conformalpy.fcod import plot_uncertainty_zones
plot_uncertainty_zones(fcod, xlabel="income")Per-class stacked bars
When comparing outcome distributions across classes, plot_stacked_bars_by_class stacks one full-width panel per class vertically, with a shared feature histogram at the bottom. This is easier to read than the side-by-side column layout produced by plot_stacked_fcod(fcod_by_class=...) when the number of grid points is large.
from conformalpy.fcod import merge_uncertain_outcomes, plot_stacked_bars_by_class
# Build per-class FCOD dicts (one compute_fcod_smoothed call per class)
fcod_by_class = {
0: merge_uncertain_outcomes(fcod_class0),
1: merge_uncertain_outcomes(fcod_class1),
}
fig = plot_stacked_bars_by_class(
fcod_by_class=fcod_by_class,
feature_values_by_class={0: X_test_c0[:, 0], 1: X_test_c1[:, 0]},
class_names={0: "Non-default", 1: "Default"},
xlabel="loan_amnt",
title="Outcome distribution by class",
alpha=0.10, # draws a dashed reference line at the conformal alpha level
)Each class panel shares the x-axis with the others and shows its own legend only on the first row to avoid repetition.
Practical Interpretation
- High SC proportion: The model is confident and correct in this region. Automation-friendly.
- High SI proportion: The model is confident but wrong — a failure mode. Investigate model behavior in this feature range.
- High MC/TS proportion: The model is uncertain. Consider routing to human review or collecting more training data in this region.
- High MU proportion (multiclass): Multi-set predictions that miss the true label — a coverage failure. May indicate distribution shift or underrepresented subgroups.
See Also
- outcomes — Outcome categorization details
- FCOD visualization example — FCOD visualization example
- FCOD model comparison example — Model comparison example