Decision Predicate Graph (DPG)
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
- Full documentation
- Quickstart
- Supported models
- Visualizations
- Examples, including local explanations
- Parameter-sensitivity benchmark
- Interactive DPG sandbox — explore how DPG turns an ensemble into a graph in the browser.
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.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dpg-0.3.6.tar.gz | 65.5 kB | Without provenance | Details for dpg-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dpg-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for dpg-0.3.6-py3-none-any.whl |
Total release size: 133.7 kB
Release files / dpg-0.3.6.tar.gz
| Download URL | dpg-0.3.6.tar.gz |
|---|---|
| Size | 65.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bae449086ab6454e0585ecb7b6b76f30ae5a7e811a7fa89b56550a43c150537
|
|
BLAKE2b-256 checksum How to use checksums |
9b5af07c3dc24e7c009abf982c9249d92875f5723ce3ae46ad37b3b39d2921d9
|
| 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.6-py3-none-any.whl
| Download URL | dpg-0.3.6-py3-none-any.whl |
|---|---|
| Size | 68.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc29b2d45783ab78210bd5ea24991eeb20b4a9a25b19681d8572e1a27f7ce9dd
|
|
BLAKE2b-256 checksum How to use checksums |
d383ae9cb6c5d6fa8213c04b18a6480058892fb3479359575673a55248106a75
|
| 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.6
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.