Skip to main content

Decision Predicate Graph (DPG)

License: MIT Install with pip Python Versions Tests Release Documentation Status Try the DPG sandbox

DPG logo

DPG is a model-agnostic framework for explaining tree ensembles. It converts their decision logic into a graph, making predicates, transitions, predictions, and structural diagnostics available in one representation.

Highlights

  • Global and local explanations through DPGExplainer
  • Graph metrics, including constraints, betweenness centrality, local reaching centrality, and communities
  • Local-path inspection, local-on-global plots, and faithfulness diagnostics
  • Support for common scikit-learn tree ensembles

Install

pip install dpg

DPG requires Python 3.10 or later. To render graphs, also install the Graphviz system package so that dot is on your PATH.

For development and documentation builds, see docs/README.md.

Quick start

import numpy as np
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from dpg import DPGExplainer

X, y = load_iris(return_X_y=True, as_frame=True)
model = RandomForestClassifier(n_estimators=5, random_state=42).fit(X, y)

explainer = DPGExplainer(
    model=model,
    feature_names=X.columns.tolist(),
    target_names=np.unique(y).astype(str).tolist(),
)
explanation = explainer.explain_global(X.values, communities=True)
explainer.plot("iris_dpg", explanation, save_dir="results")

How DPG works

The concept behind DPG is to convert a generic tree-based ensemble model for classification into a graph, where:

  • Nodes represent predicates, i.e., the feature-value associations present in each node of every tree;
  • Edges denote the frequency with which these predicates are satisfied during the model training phase by the samples of the dataset.

Metrics

The graph-based nature of DPG provides significant enhancements in the direction of a complete mapping of the ensemble structure.

Property Definition Utility
Constraints The intervals of values for each feature obtained from all predicates connected by a path that culminates in a given class. Calculate the classification boundary values of each feature associated with each class.
Betweenness centrality Quantifies the fraction of all the shortest paths between every pair of nodes of the graph passing through the considered node. Identify potential bottleneck nodes that correspond to crucial decisions.
Local reaching centrality Quantifies the proportion of other nodes reachable from the local node through its outgoing edges. Assess the importance of nodes similarly to feature importance, but enrich the information by encompassing the values associated with features across all decisions.
Community A subset of nodes of the DPG which is characterised by dense interconnections between its elements and sparse connections with the other nodes of the DPG that do not belong to the community. Understanding the characteristics of nodes to be assigned to a particular community class, identifying predominant predicates, and those that play a marginal role in the classification process.
Constraints Betweenness centrality Local reaching centrality Community
Constraints(Class 1) = val3 < F1 ≤ val1, F2 ≤ val2 BC(F2 ≤ val2) = 4/24 LRC(F1 ≤ val1) = 6 / 7 Community(Class 1) = F1 ≤ val1, F2 ≤ val2

Local explanations and faithfulness

Fit the explainer once, then inspect an individual prediction or compare local explanations with the fitted model:

explainer.fit(X.values)
local = explainer.explain_local(X.iloc[0].values, sample_id=0)
details = explainer.evaluate_faithfulness(X.values, return_details=True)

print(local.majority_vote)
print(details["faithfulness_score"])

evaluate_faithfulness reports model agreement, trace coverage, recombination, evidence margin, and a composite heuristic score. It is an explanation-fidelity measure, not a probability of ground-truth correctness.

Documentation and examples

Open the interactive DPG sandbox

The packaged CLI mirrors examples/run_dpg_standard.py. Run dpg --help for its current options and use examples/run_dpg_custom.py for a dataset with a specified target column.

Citation

If you use DPG in research, please cite:

@inproceedings{arrighi2024dpg,
  title={Decision Predicate Graphs: Enhancing Interpretability in Tree Ensembles},
  author={Arrighi, Leonardo and Pennella, Luca and Marques Tavares, Gabriel and Barbon Junior, Sylvio},
  booktitle={World Conference on Explainable Artificial Intelligence},
  pages={311--332},
  year={2024},
  isbn={978-3-031-63797-1},
  doi={10.1007/978-3-031-63797-1_16},
  publisher={Springer Nature Switzerland},
}

Metadata

Release files for dpg 0.3.5

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

Source distribution (sdist)

Source distribution for dpg 0.3.5
File Size Uploaded Provenance Actions
dpg-0.3.5.tar.gz 65.5 kB Without provenance Details for dpg-0.3.5.tar.gz

Built distribution (wheel)

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

Total release size: 133.7 kB

Release files / dpg-0.3.5.tar.gz

Download URL dpg-0.3.5.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bc5ab9e73e729e0109f4fd569b4f7e4050a371d0e5d694759445b96512977cda
BLAKE2b-256 checksum
How to use checksums
770a96bdd7c24d2d96b76c7c84d26ded1e75238f345e533caed1a22e43113339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.11.18 Linux/7.0.0-1019-azure

Release files / dpg-0.3.5-py3-none-any.whl

Download URL dpg-0.3.5-py3-none-any.whl
Size 68.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
728a12037a55ccc3ed3f91f69f8037563f42f95c2f537af87b6e4cc70972bac4
BLAKE2b-256 checksum
How to use checksums
0a8c33fa0674c98db3fe9f7287a1de69a1005e60ae90f23a236954c031fc50c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.0 CPython/3.11.18 Linux/7.0.0-1019-azure

Security for dpg 0.3.5

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.

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