{"id":27469,"library":"treeinterpreter","title":"treeinterpreter","description":"A library for interpreting scikit-learn's decision tree and random forest predictions by decomposing predictions into feature contributions. Current version 0.2.3, last updated in 2019 (maintenance mode).","status":"maintenance","version":"0.2.3","language":"python","source_language":"en","source_url":"https://github.com/andosa/treeinterpreter","tags":["interpretability","scikit-learn","random-forest","decision-tree"],"install":[{"cmd":"pip install treeinterpreter","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Required for model objects","package":"scikit-learn","optional":false},{"reason":"Required for array operations","package":"numpy","optional":false}],"imports":[{"note":"The module name and function name are both 'treeinterpreter', causing confusion. Use alias for clarity.","wrong":"import treeinterpreter","symbol":"treeinterpreter","correct":"from treeinterpreter import treeinterpreter as ti"}],"quickstart":{"code":"from sklearn.ensemble import RandomForestRegressor\nfrom sklearn.datasets import load_boston\nfrom treeinterpreter import treeinterpreter as ti\n\nboston = load_boston()\nX, y = boston.data, boston.target\nrf = RandomForestRegressor()\nrf.fit(X, y)\nprediction, bias, contributions = ti.predict(rf, X[:1])\nprint('Prediction:', prediction)\nprint('Bias:', bias)\nprint('Feature contributions:', contributions)","lang":"python","description":"Train a random forest on Boston housing data and interpret a single prediction."},"warnings":[{"fix":"Consider alternatives like shap or interpretml for newer scikit-learn.","message":"The library is unmaintained since 2019 and may not work with recent scikit-learn versions (e.g., >0.24). Expect compatibility issues.","severity":"deprecated","affected_versions":">=0.2.3"},{"fix":"Import with alias as shown.","message":"Duplicate naming: the module 'treeinterpreter' contains a function also named 'treeinterpreter'. Use 'from treeinterpreter import treeinterpreter as ti' to avoid confusion.","severity":"gotcha","affected_versions":"all"},{"fix":"Downgrade scikit-learn to <=0.23 or patch the library. Use shap as alternative.","message":"Scikit-learn v0.24+ deprecated certain internal APIs used by treeinterpreter, causing AttributeError: 'ForestClassifier' object has no attribute 'estimators_' (in some contexts).","severity":"breaking","affected_versions":"scikit-learn >=0.24"},{"fix":"Ensure your model is a tree-based ensemble.","message":"The library only supports tree-based models from scikit-learn (RandomForest, ExtraTrees, DecisionTree). Does not work with other models.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use 'from treeinterpreter import treeinterpreter as ti' then 'ti.predict()'.","cause":"Incorrect import statement (import treeinterpreter then calling treeinterpreter.treeinterpreter).","error":"AttributeError: module 'treeinterpreter' has no attribute 'treeinterpreter'"},{"fix":"Downgrade scikit-learn to 0.23.2 or use a different interpretation library.","cause":"Incompatible scikit-learn version (>=0.24) where estimators_ property changed.","error":"AttributeError: 'RandomForestRegressor' object has no attribute 'estimators_'"},{"fix":"Reshape your input: X[:1] instead of X[0]. Use X.values.reshape(1, -1) for pandas.","cause":"Typically when passing a single sample but expecting 2D array.","error":"ValueError: could not broadcast input array from shape (n,) into shape (m,)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}