Created
December 22, 2021 07:18
-
-
Save yptheangel/f9e61a8b54feeb8c2b82a4fd1f0c7dd0 to your computer and use it in GitHub Desktop.
shap feature importance
This file contains 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
import numpy as np | |
import pandas as pd | |
import shap | |
explainer = shap.TreeExplainer("your_tree_model") | |
shap_values = explainer.shap_values(X_train) | |
scores= np.abs(shap_values).mean(0) | |
feature_importance = pd.DataFrame(list(zip(X_train.columns, sum(scores))), columns=['feature','feature_importance_score']) | |
feature_importance.sort_values(by=['feature_importance_score'], ascending=False,inplace=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment