fpde.
fpde and fpde.core.
FPDEEngine
Use FPDEEngine for repeated explanations, batch explanations, Hyb-FPDE, grid search, validation-based lambda selection, and Bayesian-FPDE lambda posterior selection.
FPDEEngine.fit
| Parameter | Description |
|---|---|
X_train | Training feature matrix with shape (n_samples, n_features). |
y_train | Training labels with one label per row in X_train. |
model | Optional classifier. Required later when an operation needs predict_proba. |
baseline | Optional replacement vector for perturbation curves. Defaults to the training mean. |
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.
engine.select_bayesian_lambda
lambda_hyb candidates using the same held-out deletion and insertion validation score as select_lambda.
| Parameter | Description |
|---|---|
alpha | Positive alpha parameter for the Beta prior on lambda_hyb. |
beta | Positive beta parameter for the Beta prior on lambda_hyb. |
temperature | Positive likelihood temperature. Smaller values make the posterior sharper. |
credible_mass | Credible interval mass in (0, 1). |
BayesianFPDELambdaSelectionResult.
engine.explain_one_bayesian
selection.posterior_mean_lambda, where selection is a BayesianFPDELambdaSelectionResult.
Returns (attributions, details).
The details dictionary includes the usual fixed-lambda fields plus lambda_source, posterior_mean_lambda, map_lambda, credible_interval, posterior_entropy, and effective_candidates.
engine.explain_batch_bayesian
lambda_hyb.
Returns (attribution_matrix, details).
engine.explain_matrix_bayesian
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
Result objects
| Object | Contains |
|---|---|
FPDEExplanation | mode, evidence, attributions, positive_score, negative_score, labels, prototype indices, exactness_residual, and method details. |
FPDEContext | Prototypes, prototype labels, mean anchor, zero anchor, baseline, and feature count. |
HybFPDEGridSearchResult | best_config, best_score, rows, objective, n_candidates, and n_eval_samples. |
HybFPDEValidationSelectionResult | best_lambda, best_config, rows, and n_eval_samples. |
BayesianFPDELambdaSelectionResult | posterior_mean_lambda, map_lambda, credible_interval, posterior_rows, prior_alpha, prior_beta, temperature, normalize, anchor_strategy, eps, and n_eval_samples. Call sorted_rows() to inspect candidates from highest to lowest posterior probability. |
Common errors
| Error | Cause | Fix |
|---|---|---|
model must implement predict_proba | A model-dependent operation was called without probability support. | Pass a fitted classifier with predict_proba. |
model must expose classes_ | The model does not expose class labels. | Use a scikit-learn-style classifier or add compatible classes_ metadata. |
feature dimension mismatch | Input vectors do not match the fitted training feature count. | Apply the same preprocessing pipeline to training, validation, and explanation data. |
lambda_hyb must be in [0, 1] | The Hyb-FPDE mixture weight is outside the valid range. | Pass a finite value from 0.0 to 1.0. |
eps must be positive | Cosine regularization was zero or negative. | Use a positive eps, such as 1e-12. |