A model-agnostic graph framework for global and local explanation of tree-based ensembles. DPG turns an ensemble's decision logic into one graph of predicates, transitions and predictions you can inspect.

  • XAI
  • Tree ensembles
  • Graph theory
  • Explainability
pip install dpg

dpg 0.3.4 on PyPI · Python 3.10+ · MIT license

A random forest with 5 trees on Iris, coloured by community. Each node is a predicate such as petal length (cm) <= 2.45, each edge weight counts the training samples that took that transition, and every path ends in a class.

How it works

  1. Tabular datasetfeatures + labels
  2. Tree-based ensembleRF · GB · ET · AdaBoost · Bagging
  3. Predicate extractionpaths → nodes and edges
  4. DPG constructionweighted graph
  5. Analysis & insightscentrality · communities · local paths

Nodes are the predicates found in every node of every tree. Edges count how often the training samples satisfy one predicate after another.

What the graph tells you

Constraints

The value intervals of each feature along every path that ends in a class, i.e. the classification boundaries of each class.

Betweenness centrality

The share of shortest paths passing through a node. High values flag bottleneck predicates: the crucial decisions.

Local reaching centrality

How much of the graph a node reaches. Like feature importance, but tied to the feature values used in every decision.

Communities

Densely connected groups of predicates per class, separating the dominant decisions from the marginal ones.

Beyond the global graph: local explanations per sample, local-on-global plots, and faithfulness diagnostics. See the visualization guide.

Get started

1 Install the package

pip install dpg

Requires Python 3.10 or newer.

2 Add Graphviz for rendering

The dot executable must be on your PATH to draw graphs.

macOS
brew install graphviz
Ubuntu / Debian
sudo apt-get install graphviz
Windows
winget install Graphviz.Graphviz

3 Explain a random forest

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from dpg import DPGExplainer

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

explainer = DPGExplainer(
    model=model,
    feature_names=X.columns.tolist(),
    target_names=[n.capitalize() for n in iris.target_names],
)
explanation = explainer.explain_global(X.values, communities=True)
explainer.plot_communities("iris_dpg", explanation, save_dir="results")

This writes the community graph shown above to results/. Prefer the terminal? The dpg command does the same:

dpg --dataset iris --n_learners 5 --plot --communities

Cite DPG

If you use DPG in your research, please cite Decision Predicate Graphs: Enhancing Interpretability in Tree Ensembles (World Conference on Explainable AI, 2024).

BibTeX

@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},
}