Skip to main content
Use FPDEEngine for most workflows. It stores prototypes, anchors, the baseline vector, and label lookup state so you can reuse them across explanations.

Explain one sample

details["target_label"] is the model’s highest-probability class. details["rival_label"] is the second-highest-probability class.

Explain a batch

Use explain_batch when you need both attribution rows and per-sample metadata.
Use explain_matrix when you only need the attribution matrix.

Select lambda_hyb

Use held-out validation data to select a fixed Hyb-FPDE mixture. The selection score combines deletion and insertion perturbation curves.
Save selection.rows with your experiment results so you can inspect the score for each candidate later. Use grid_search to compare Diff-FPDE, Cos-FPDE, and Hyb-FPDE candidate settings.

Direct prototype functions

Use lower-level functions when you want direct control over prototypes and labels.
For repeated work, prefer FPDEEngine.

Visualize explanations

The plotting helpers exported from fpde and the compact fpde.plots namespace render FPDE attributions, prototype similarities, and perturbation curves with matplotlib. Install the optional plot extra first:
Each helper returns a matplotlib Axes you can save or arrange in a subplot.

Local attribution bar and waterfall

Use plot_attributions for a signed bar chart of one explanation, and plot_attribution_waterfall for a cumulative view.

Batch summary with beeswarm

Use fpde.plots.beeswarm to summarize per-sample contributions across a batch, colored by feature value.

Prototype similarity distribution

Use plot_prototype_similarity_distribution to see how the explained sample sits between the target and rival prototypes.

Attribution heatmap for image features

When features form an image, reshape the attribution vector with plot_attribution_image.

Perturbation curves

After computing deletion and insertion curves, visualize them with plot_perturbation_curves.

Full notebook

For an end-to-end walkthrough covering bar, waterfall, beeswarm, similarity, image, and perturbation plots on the breast cancer dataset, see examples/plot_fpde_example.ipynb in the FPDE repository.