Skip to main content

Feature Prototype Direction Explainer (FPDE)

PyPI version Python versions License

Feature Prototype Direction Explainer (FPDE) is a Python package for prototype-contrast feature attribution. It explains a classification result by comparing an input with a prototype for the target class and a prototype for a rival class, then decomposing that contrast into per-feature contributions.

Use FPDE when you want a lightweight, post-hoc explanation method for tabular-style feature vectors and black-box classifiers that expose class probabilities.

What You Can Do

  • Build class-mean prototypes from training data.
  • Explain one sample with Diff-FPDE, Cos-FPDE, or a fixed Hyb-FPDE mixture.
  • Explain batches while reusing fitted prototype state.
  • Search Diff, Cos, and Hyb-FPDE candidate settings.
  • Select lambda_hyb with held-out deletion and insertion validation.
  • Compute deletion and insertion perturbation curves for an attribution vector.

Install FPDE

FPDE requires Python 3.12 or newer.

python -m pip install fpde

For local development, clone the repository and install it in editable mode:

python -m pip install -e .

The PyPI distribution name and Python import package are both fpde.

Quick Start

This example trains a scikit-learn classifier, fits an FPDE engine on the training data, and explains one test sample.

import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

from fpde import FPDEEngine

data = load_breast_cancer()
X_train, X_test, y_train, _ = train_test_split(
    data.data,
    data.target,
    test_size=0.25,
    random_state=7,
    stratify=data.target,
)

scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

model = LogisticRegression(max_iter=2000, random_state=7)
model.fit(X_train, y_train)

engine = FPDEEngine.fit(X_train, y_train, model=model)
attributions, details = engine.explain_one(X_test[0], lambda_hyb=0.5)

print(np.asarray(attributions))
print(details["target_label"], details["rival_label"], details["evidence"])

Positive attribution values support the target class relative to the rival class. Negative values support the rival class relative to the target class.

Run The Example

python examples/minimal_fpde_example.py

The script prints the predicted class and the largest positive and negative feature contributions for one sample from the breast cancer dataset bundled with scikit-learn.

Documentation

Test The Package

Install the development dependencies, then run the test suite:

python -m pip install -e .
python -m pytest

You can also run the repository in Docker:

docker build -t fpde .
docker run --rm fpde

The Docker command runs the test suite and the minimal example.

Cite FPDE

If you use FPDE in academic work, cite the software or method as appropriate. Citation metadata is available in CITATION.cff.

License

FPDE is distributed under a dual license: MIT OR Apache-2.0. You may choose either license. See LICENSE, LICENSE-MIT, and LICENSE-APACHE.

Metadata

Release files for fpde 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fpde 0.1.0
File Size Uploaded Provenance Actions
fpde-0.1.0.tar.gz 37.2 kB Without provenance Details for fpde-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fpde 0.1.0
File Interpreter ABI Platform Actions
fpde-0.1.0-py3-none-any.whl Python 3 none any Details for fpde-0.1.0-py3-none-any.whl

Total release size: 74.1 kB

Release files / fpde-0.1.0.tar.gz

Download URL fpde-0.1.0.tar.gz
Size 37.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4c0a2258c4af82899662712abe55652cdf708e85168ffa76104273e0c2254f08
BLAKE2b-256 checksum
How to use checksums
f1bab8fca2029b1f67701a3942507ad39dc27dfb370e9e6b0c8afd3f32392327
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fpde-0.1.0-py3-none-any.whl

Download URL fpde-0.1.0-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5973e0bb5a2fabcb8a090fddb1a43338c6546db457c28cc954de7aeccb66d8e7
BLAKE2b-256 checksum
How to use checksums
b3a2afadddfb14b5be127f85e9f2a954eb4884d74b09a307ab2aed1030b05125
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fpde 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page