Created
February 11, 2019 22:24
-
-
Save erykml/ffc69f6a6166f2ce25e56fdd11bf091a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from treeinterpreter import treeinterpreter as ti, utils | |
| selected_rows = [31, 85] | |
| selected_df = X_train.iloc[selected_rows,:].values | |
| prediction, bias, contributions = ti.predict(rf, selected_df) | |
| for i in range(len(selected_rows)): | |
| print("Row", selected_rows[i]) | |
| print("Prediction:", prediction[i][0], 'Actual Value:', y_train[selected_rows[i]]) | |
| print("Bias (trainset mean)", bias[i]) | |
| print("Feature contributions:") | |
| for c, feature in sorted(zip(contributions[i], | |
| X_train.columns), | |
| key=lambda x: -abs(x[0])): | |
| print(feature, round(c, 2)) | |
| print("-"*20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment