Constraints
The value intervals of each feature along every path that ends in a class, i.e. the classification boundaries of each class.
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.
pip install dpg
petal length (cm) <= 2.45, each edge weight counts the training samples that took that
transition, and every path ends in a class.Nodes are the predicates found in every node of every tree. Edges count how often the training samples satisfy one predicate after another.
The value intervals of each feature along every path that ends in a class, i.e. the classification boundaries of each class.
The share of shortest paths passing through a node. High values flag bottleneck predicates: the crucial decisions.
How much of the graph a node reaches. Like feature importance, but tied to the feature values used in every decision.
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.
pip install dpg
Requires Python 3.10 or newer.
The dot executable must be on your PATH to draw graphs.
brew install graphvizsudo apt-get install graphvizwinget install Graphviz.Graphvizfrom 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
If you use DPG in your research, please cite Decision Predicate Graphs: Enhancing Interpretability in Tree Ensembles (World Conference on Explainable AI, 2024).
@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},
}