FDFI Documentation

License: MIT Python 3.8+

FDFI (Flow-Disentangled Feature Importance) is a Python library for computing feature importance using disentangled methods, inspired by SHAP. This package implements both OT-based DFI and flow-based FDFI methods.

Key Features

  • 🎯 Multiple Explainer Types: Tree, Linear, Kernel, and Optimal Transport explainers

  • 🧭 OT-Based DFI: Gaussian OT (OTExplainer) and Entropic OT (EOTExplainer)

  • 🔍 Shared Diagnostics: Latent independence and fidelity checks for OT/EOT/Flow

  • 📊 Visualization: Summary, waterfall, force, dependence, CI, and diagnostics plots

  • 📊 Statistical Inference: Confidence intervals and hypothesis testing

  • 🔧 Easy to Use: Simple API similar to SHAP

  • 🚀 Extensible: Built with modularity for future enhancements

Quick Example

import numpy as np
from fdfi.explainers import OTExplainer
from fdfi.plots import summary_bar

# Define your model
def model(X):
    return X.sum(axis=1)

# Create background data
X_background = np.random.randn(100, 10)

# Create an explainer
explainer = OTExplainer(model, data=X_background, nsamples=50)

# Explain test instances
X_test = np.random.randn(10, 10)
results = explainer(X_test)

# Get confidence intervals
ci = explainer.conf_int(alpha=0.05, target="X", alternative="two-sided")

# Visualize global scores
feature_names = [f"X{i}" for i in range(X_background.shape[1])]
summary_bar(results["phi_X"], results["se_X"], feature_names, show=False)

Installation

git clone https://github.com/jaydu1/FDFI.git
cd FDFI
pip install -e .

# With optional dependencies
pip install -e ".[flow]"    # For flow matching models
pip install -e ".[dev]"     # For development

Development

Indices and tables