Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
treeinterpreter
✓ import treeinterpreter
✗ from treeinterpreter import treeinterpreter as ti
Train a random forest on Boston housing data and interpret a single prediction.
from sklearn.ensemble import RandomForestRegressor
from sklearn.datasets import load_boston
from treeinterpreter import treeinterpreter as ti
boston = load_boston()
X, y = boston.data, boston.target
rf = RandomForestRegressor()
rf.fit(X, y)
prediction, bias, contributions = ti.predict(rf, X[:1])
print('Prediction:', prediction)
print('Bias:', bias)
print('Feature contributions:', contributions)
Debug
Known issues
deprecatedThe library is unmaintained since 2019 and may not work with recent scikit-learn versions (e.g., >0.24). Expect compatibility issues.fixConsider alternatives like shap or interpretml for newer scikit-learn.
affects: >=0.2.3
gotchaDuplicate naming: the module 'treeinterpreter' contains a function also named 'treeinterpreter'. Use 'from treeinterpreter import treeinterpreter as ti' to avoid confusion.fixImport with alias as shown.
affects: all
breakingScikit-learn v0.24+ deprecated certain internal APIs used by treeinterpreter, causing AttributeError: 'ForestClassifier' object has no attribute 'estimators_' (in some contexts).fixDowngrade scikit-learn to <=0.23 or patch the library. Use shap as alternative.
affects: scikit-learn >=0.24
gotchaThe library only supports tree-based models from scikit-learn (RandomForest, ExtraTrees, DecisionTree). Does not work with other models.fixEnsure your model is a tree-based ensemble.
affects: all
Upgrade
Version history
0.2.3latest on PyPI · released Jan 10, 2021
Audit
Dependencies
scikit-learnrequiredRequired for model objects
numpyrequiredRequired for array operations