fpde.
fpde and fpde.core.
FPDEEngine
Use FPDEEngine for repeated explanations, batch explanations, Hyb-FPDE, grid search, and validation-based lambda selection.
FPDEEngine.fit
Returns an
FPDEEngine.
engine.explain_one
(attributions, details).
The details dictionary includes target_label, rival_label, target_probability, lambda_hyb, evidence, exactness_residual, positive_score, and negative_score.
engine.explain_batch
(attribution_matrix, details).
If include_details=False, details is an empty list.
engine.explain_matrix
engine.grid_search
HybFPDEGridSearchResult.
engine.select_lambda
lambda_hyb by held-out deletion and insertion validation.
Returns a HybFPDEValidationSelectionResult.
Prototype helpers
class_mean_prototypes
(prototypes, labels).
select_prototype_pair
(positive_index, negative_index).
prepare_fpde_context
FPDEContext.
Explanation functions
Use these functions when you want direct control over prototypes and labels.diff_fpde
cos_fpde
explain_with_selected_prototypes
FPDEEngine for Hyb-FPDE.
Metrics and probability helpers
regularized_cosine
top_two_labels
(target_label, rival_label, probability_vector) for one sample.
model must implement predict_proba and expose classes_.
predict_proba_for_label
predict_proba(X) column for label.
perturbation_curves
Plotting helpers
The plotting helpers are exported fromfpde and visualize FPDE attributions, prototype similarities, and perturbation curves with matplotlib.
They require the optional plot extra:
Axes it draws on and does not call plt.show() or save files.
Pass an existing ax= to draw into a subplot, or omit it to create a new figure.
plot_attributions
FPDEExplanation.
Positive values support the target class; negative values support the rival class.
Use top_k to limit the number of features and normalize=True to L1-normalize the displayed values.
plot_attribution_waterfall
base_value to base_value + sum(attributions).
Hidden features (outside top_k) are grouped into one other features bar.
plot_attribution_summary
feature_values with the same shape as attributions to color points by the original feature value.
plot_attribution_image
shape=(height, width) for flat image vectors; shape is optional for already-2D arrays.
plot_perturbation_curves
perturbation_curves.
curves must contain fractions, deletion_prob, and insertion_prob.
plot_local_contributions
values to label each bar with the corresponding feature value.
prepare_local_contribution_data
feature, display_name, contribution, abs_contribution, direction, direction_label) suitable for rendering FPDE local attributions in a custom UI.
plot_prototype_similarity_distribution
X to the target prototype.
Pass rival_prototype to overlay the rival distribution and x to mark the explained sample.
metric is "cosine" or "negative_euclidean".
fpde.plots namespace
fpde.plots provides a compact matplotlib API for FPDE contribution arrays inspired by SHAP’s plotting layout.
Pass show=False to receive an Axes without displaying, then save with ax.figure.savefig(...).