Skip to content

Instantly share code, notes, and snippets.

@roma-glushko
Created January 11, 2021 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roma-glushko/20d7bb27d5249f43ce647fdd402c6c5f to your computer and use it in GitHub Desktop.
Save roma-glushko/20d7bb27d5249f43ce647fdd402c6c5f to your computer and use it in GitHub Desktop.
import shap
shap.initjs()
# Create object that can calculate shap values
explainer = shap.TreeExplainer(rf_classifier)
# Calculate Shap values
shap_values = explainer.shap_values(X_test, y_test)
# show feature importance for 0 class
shap.summary_plot(shap_values[0], X_test_transformed)
# show decision path for 30th example and 2nd class
shap.decision_plot(explainer.expected_value[2], shap_values[2][30, :], X_test_transformed.iloc[30, :])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment