Skip to main content

Greedy-Prune-Explain: Minimal local explanations for decision tree predictions

Project description

GPE Framework - Greedy-Prune-Explain

Python 3.8+ License: MIT PyPI version

GPE (Greedy-Prune-Explain) is a novel method for generating minimal, interpretable local explanations for decision tree predictions. Unlike existing methods like LIME, SHAP, or Anchors, GPE leverages the inherent structure of decision trees to produce explanations that are:

  • Minimal — Contains only essential conditions (1-2 instead of 5)
  • Precise — 99.4% precision on real-world financial data
  • Fast — 48x faster than LIME, 19x faster than Anchors
  • Actionable — Simple IF-THEN rules like "income < 50000 AND debt_ratio > 0.4"

📊 Benchmark Results

Tested on 3 financial datasets (632K records total):

Method Time (ms) Complexity Precision Speedup
GPE-Core 4.4 1.4 99.4% 48x
GPE-IT 3.0 1.4 97.9% 71x
LIME 213 5.0 1x
Anchors 82 0.7 99.2% 3x

All results are statistically significant (p < 0.001)

🚀 Installation

pip install gpe-framework

Or install from source:

git clone https://github.com/vladdehtiarov/gpe-framework.git
cd gpe-framework
pip install -e .

📖 Quick Start

from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris
from gpe import GPEExplainer

# Load data and train model
iris = load_iris()
X, y = iris.data, iris.target
model = DecisionTreeClassifier(max_depth=5)
model.fit(X, y)

# Create explainer
explainer = GPEExplainer(
    model=model,
    feature_names=iris.feature_names,
    X_train=X,
    min_precision=0.95
)

# Explain a prediction
explanation = explainer.explain(X[0])
print(explanation)

Output:

============================================================
GPE Explanation (method: GPE)
============================================================
Prediction: 0
Rule: petal length (cm) <= 2.45
------------------------------------------------------------
Precision: 100.00%
Coverage: 33.33%
Complexity: 1 conditions
Reduction: 75.0% (4 → 1 conditions)
============================================================

Natural Language Output

print(explanation.to_natural_language())
The model predicts 'setosa' because petal length is at most 2.45.
This explanation covers 33.3% of similar cases with 100.0% accuracy.

🔧 GPE Variants

from gpe import (
    GPEExplainer,            # Standard (fast, greedy)
    GPEInformationTheoretic, # Uses mutual information for pruning
    GPECounterfactual,       # Adds counterfactual explanations
    GPEOptimal,              # Exhaustive search for minimal rule
    GPEEnsemble              # For Random Forest, XGBoost
)

# GPE-IT: Uses mutual information I(condition; prediction)
gpe_it = GPEInformationTheoretic(model, feature_names=features, X_train=X)
explanation = gpe_it.explain(x)

# GPE-CF: Includes counterfactual explanation
gpe_cf = GPECounterfactual(model, feature_names=features, X_train=X)
cf_explanation = gpe_cf.explain_with_counterfactual(x)
print(f"To change the decision: {cf_explanation.changes}")

📖 How It Works

GPE operates in three phases:

1. GREEDY Phase

Extract the full decision path from root to leaf:

Root → income <= 50000 → debt_ratio > 0.4 → ... → Leaf (denied)

2. PRUNE Phase

Iteratively remove conditions that don't affect precision:

while conditions > 1:
    for condition in rule:
        precision_without = calculate_precision(rule - condition)
        if precision_without >= threshold:
            remove(condition)

3. EXPLAIN Phase

Return the minimal rule with metrics:

  • Precision — Accuracy for instances satisfying the rule
  • Coverage — Proportion of dataset satisfying the rule
  • Complexity — Number of conditions

📊 Metrics

from gpe import (
    precision_score,
    coverage_score,
    complexity_score,
    fidelity_score,
    stability_score
)

# Evaluate explanation quality
precision = precision_score(explanation, model, X)
coverage = coverage_score(explanation, X)
complexity = complexity_score(explanation)

🔬 Scientific Novelty

  1. GPE-Core — First local explanation method specifically designed for decision trees
  2. GPE-IT — Novel use of mutual information I(condition; prediction) for condition selection
  3. Theoretical guarantees — Proven precision bounds and O(n·d) complexity
  4. Practical efficiency — 48x faster than LIME on real data

📁 Project Structure

gpe-framework/
├── gpe/
│   ├── __init__.py          # Public API
│   ├── core.py              # GPEExplainer
│   ├── novel_methods.py     # GPE-IT, GPE-CF (scientific contribution)
│   ├── variants.py          # GPEOptimal, GPEWeighted
│   ├── explanation.py       # Data structures
│   ├── metrics.py           # Evaluation metrics
│   ├── tree_utils.py        # Tree utilities
│   └── visualization.py     # Plotting functions
├── tests/                   # Unit tests
├── experiments/             # Benchmark scripts
└── docs/                    # Documentation

🤝 Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests.

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Format code
black gpe/

📜 License

MIT License - see LICENSE file for details.

👤 Author

Vladyslav Dehtiarov

📚 Citation

If you use GPE in your research, please cite:

@article{dehtiarov2025gpe,
  title={Greedy-Prune-Explain: Minimal Local Explanations for Decision Tree Predictions},
  author={Dehtiarov, Vladyslav and Borovyk, Valentyna},
  journal={International Journal of Artificial Intelligence Research},
  year={2025}
}

🔗 Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpe_framework-1.0.1.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpe_framework-1.0.1-py3-none-any.whl (42.5 kB view details)

Uploaded Python 3

File details

Details for the file gpe_framework-1.0.1.tar.gz.

File metadata

  • Download URL: gpe_framework-1.0.1.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gpe_framework-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ac9098b8562615c8e623b86b4b8dd87f082a055a0a9012cd82309d11b8501c67
MD5 9e4b5d82d58b5a077d21b0ec8114f239
BLAKE2b-256 4b116dbba17ef963ce63bdc6541fa80a38486fa5cd7fcc1b5a57203b23683d4e

See more details on using hashes here.

File details

Details for the file gpe_framework-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gpe_framework-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 42.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for gpe_framework-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0d240343ad0642639086e94a176b6626c4ac683a4fe0b780c3c326595eecdba9
MD5 7495a07be7f4668a6ec23a52b4e016eb
BLAKE2b-256 97bc5c94b7ea6453b138871b65373dd371281c5e9eda2e549c408ab2c19afc3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page