When to use FPDE
Use FPDE when you have:- A feature matrix where each column has a consistent meaning.
- Class labels for training samples.
- A classification model, usually one that exposes
predict_proba. - A need to explain target-versus-rival evidence at the feature level.
Core terms
| Term | Meaning |
|---|---|
| Prototype | A representative feature vector for a class. FPDE currently builds one class-mean prototype per class. |
| Target class | The class being explained, often the classifier’s predicted class. |
| Rival class | The contrast class, often the second-highest-probability class. |
| Evidence | The scalar target-versus-rival contrast decomposed by FPDE. |
| Attribution | A per-feature contribution to the evidence value. |
| Anchor | A reference vector used by Cos-FPDE before computing cosine contrasts. |
| Baseline | A replacement vector used for deletion and insertion perturbation curves. |
Prototype construction
class_mean_prototypes(X, y) computes one prototype per class by averaging all training rows with that class label.
FPDEEngine.fit(X_train, y_train, model) builds the same prototype state and stores it for repeated explanations.
For repeated workflows, prefer FPDEEngine because it reuses:
- Class-mean prototypes
- Prototype labels
- Mean and zero anchors
- The baseline vector
- Label-to-prototype lookup state
Target and rival selection
When you useFPDEEngine with a model, FPDE chooses the local contrast from predict_proba.
When you call lower-level functions directly, pass
positive_label and negative_label.
If you omit negative_label, FPDE selects a non-target prototype according to the selected mode.
Diff-FPDE
Diff-FPDE decomposes the difference in squared distances from the input to the rival and target prototypes.Cos-FPDE
Cos-FPDE decomposes a regularized cosine-similarity contrast.Hyb-FPDE
Hyb-FPDE mixes Diff-FPDE and Cos-FPDE attribution vectors.lambda_hyb must be in [0, 1].
lambda_hyb=1.0uses the Diff-FPDE endpoint.lambda_hyb=0.0uses the Cos-FPDE endpoint.- Intermediate values blend both attribution vectors.
normalize="none" when you want to mix the raw component scales.
Bayesian-FPDE
Bayesian-FPDE replaces a single selectedlambda_hyb with a posterior distribution over the lambda grid.
Use it when you want to express uncertainty about the Hyb-FPDE mixture weight, or when you want a Bayesian model-averaged attribution instead of a point-selected one.
FPDEEngine.select_bayesian_lambda evaluates the same held-out deletion and insertion validation score as select_lambda, then converts the finite lambda grid into a posterior.
The default prior is Beta(1, 1), which is uniform over the candidates.
For each candidate, the unnormalized log-posterior is:
alpha and beta to encode prior preferences over lambda_hyb.
Smaller temperature values make the posterior sharper around high-scoring candidates; larger values flatten it toward the prior.
The normalized posterior weights produce:
posterior_mean_lambda: the Bayesian model-averaged mixture weight.map_lambda: the highest-posterior lambda candidate.credible_interval: an equal-tail credible interval on the grid for the chosencredible_mass.posterior_rows: candidate rows with validation metrics and posterior mass.
engine.explain_one_bayesian, engine.explain_batch_bayesian, and engine.explain_matrix_bayesian use posterior_mean_lambda.
Because Hyb-FPDE is linear in lambda_hyb, this is equivalent to the expected attribution vector under the lambda posterior.
Interpreting results
An FPDE explanation contains:attributions: one contribution per featureevidence: the sum of the attribution vector for the selected contrastpositive_scoreandnegative_score: the target and rival side scoresexactness_residual: numerical difference between summed attribution and direct evidence- Prototype labels and prototype indices
FPDEExplanation.normalized_attributions returns an L1-normalized attribution vector.
Use it for plotting, not as the raw evidence scale.