Package for interpreting scikit-learn's decision tree and random forest predictions.
Project description
Package for interpreting scikit-learn’s decision tree and random forest predictions. Allows decomposing each prediction into bias and feature contribution components as described in http://blog.datadive.net/interpreting-random-forests/. For a dataset with n features, each prediction on the dataset is decomposed as prediction = bias + feature_1_contribution + ... + feature_n_contribution.
It works on scikit-learn’s
- DecisionTreeRegressor
- DecisionTreeClassifier
- ExtraTreeRegressor
- ExtraTreeClassifier
- RandomForestRegressor
- RandomForestClassifier
- ExtraTreesRegressor
- ExtraTreesClassifier
Free software: BSD license
Dependencies
- scikit-learn 0.17+
Installation
The easiest way to install the package is via pip:
$ pip install treeinterpreter
Usage
from treeinterpreter import treeinterpreter as ti # fit a scikit-learn's regressor model rf = RandomForestRegressor() rf.fit(trainX, trainY) prediction, bias, contributions = ti.predict(rf, testX)
Prediction is the sum of bias and feature contributions:
assert(numpy.allclose(prediction, bias + np.sum(contributions, axis=1))) assert(numpy.allclose(rf.predict(testX), bias + np.sum(contributions, axis=1)))
More usage examples at http://blog.datadive.net/random-forest-interpretation-with-scikit-learn/.
History
0.1.0 (2015-07-22)
- First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
| Filename, size | File type | Python version | Upload date | Hashes |
|---|---|---|---|---|
| Filename, size treeinterpreter-0.2.2-py2.py3-none-any.whl (6.2 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
| Filename, size treeinterpreter-0.2.2.zip (10.2 kB) | File type Source | Python version None | Upload date | Hashes View |
Hashes for treeinterpreter-0.2.2-py2.py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | a23bc89a3a7bd2ff8ec7973bb7947c7a5a4b74948f0613acfeac762b83f08555 |
|
| MD5 | 62992e426fd0a37117042307a3bbe163 |
|
| BLAKE2-256 | 56cb78ec761719d2546d4bb75ec02773d01c0a0e8229fe3f8edf6a6ac961e24e |