fcod

fcod

Feature-Conditioned Outcome Distribution (FCOD) for conformal prediction.

This module provides tools for computing and visualizing Feature-Conditioned Outcome Distributions (FCODs) that show how the proportion of each conformal outcome varies with feature values.

For binary classification, outcomes are: SC, SI, TS0, TS1, Empty. For multiclass classification (K>2), outcomes are: SC, SI, MC, MU, Empty.

Unlike traditional Partial Dependence Plots (Friedman, 2001) that show expected predictions marginalized over other features, FCODs compute the conditional empirical distribution of conformal outcomes at each feature value.

References

Caparrini, A., Ariza-Garzón, M.-J., & Arroyo, J. (2026). Explaining Conformal Prediction: Diagnosing Reliability through Feature-Conditioned Outcomes and p-Value Margins. COPA, PMLR 329.

Core FCOD Computation: - compute_fcod: Basic FCOD computation - compute_fcod_smoothed: Smoothed FCODs for publication - compute_multi_feature_fcod: FCODs for multiple features - compute_interaction_fcod: 2D interaction FCODs - merge_uncertain_outcomes: Merge TS0+TS1 → TS (binary only)

Confidence Intervals: - bootstrap_fcod_ci: Bootstrap-based confidence intervals - pointwise_binomial_ci: Analytical binomial intervals - compute_fcod_with_ci: Convenience wrapper - multi_feature_fcod_with_ci: Multiple features with CI

Visualization: - plot_fcod: Plot FCOD curves with CI bands (supports class-split via fcod_by_class) - plot_stacked_fcod: Stacked area chart (supports class-split via fcod_by_class) - plot_stacked_bars_by_class: Vertically-stacked bar rows, one per class, with shared histogram - plot_model_comparison_fcod: Compare models - plot_multi_feature_fcod: Grid of feature FCODs - plot_interaction_fcod: 2D interaction heatmap - plot_uncertainty_zones: Decision zone visualization - plot_stacked_fcod_paired: Deprecated — use plot_stacked_fcod(fcod_by_class=...) - plot_stacked_fcod_by_class: Deprecated — use plot_stacked_fcod in a loop

Example

import numpy as np from conformalpy.fcod import compute_fcod_with_ci, plot_fcod

Compute FCOD with bootstrap confidence intervals

feature = np.random.randn(1000) pred_sets = [{0} if f > 0 else {0, 1} for f in feature] y_true = np.random.randint(0, 2, 1000)

fcod = compute_fcod_with_ci(feature, pred_sets, y_true, n_bootstrap=100) ax = plot_fcod(fcod, xlabel=“Feature X”) plt.show()