> ## Documentation Index
> Fetch the complete documentation index at: https://fpde-80-mintlify-8d7c1d86.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Install FPDE and explain one scikit-learn classification result

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

The example uses the breast cancer dataset bundled with scikit-learn.

## Prerequisites

Before you begin, install:

* Python 3.12 or newer
* `pip`
* A classifier that exposes `predict_proba` and `classes_`

## Get started

<Steps>
  <Step title="Install">
    Install FPDE from PyPI.

    ```bash theme={null}
    python -m pip install fpde
    ```
  </Step>

  <Step title="Train a classifier">
    Train a classifier on the same feature space you want to explain.

    ```python theme={null}
    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

    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)
    ```
  </Step>

  <Step title="Fit FPDE">
    Fit reusable FPDE state from the training data and labels.

    ```python theme={null}
    from fpde import FPDEEngine

    engine = FPDEEngine.fit(X_train, y_train, model=model)
    ```
  </Step>

  <Step title="Explain one sample">
    Explain one test sample with a fixed Hyb-FPDE mixture.

    ```python theme={null}
    import numpy as np

    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"])
    ```
  </Step>
</Steps>

## Complete example

```python theme={null}
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.

<Tip>
  Scale features before using distance-based explanations when feature units differ.
  FPDE expects training, validation, and explanation inputs to share the same feature space.
</Tip>

## Run the repository example

Clone the repository and run the minimal example.

```bash theme={null}
git clone https://github.com/fpde-xai/fpde.git
cd fpde
python -m pip install -e .
python examples/minimal_fpde_example.py
```
