Created
March 11, 2021 00:31
-
-
Save zero731/557f8e2392e82485e26df3c4a3e93225 to your computer and use it in GitHub Desktop.
plot top 10 predictive features for example churn analysis
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
## Obtain and sort feature importances from fitted model | |
feature_importances = (rf.feature_importances_) | |
sorted_idx = feature_importances.argsort() | |
importance = pd.Series(feature_importances, index=feature_names) | |
## Plot top 10 most predictive features | |
plt.figure(figsize=(10,8)) | |
fig = importance.sort_values().tail(10).plot(kind='barh') | |
fig.set_title('Top 10 Most Predictive Features', | |
fontsize=16, fontweight='bold') | |
plt.xticks(fontsize=12, fontweight='bold') | |
plt.yticks(fontsize=12, fontweight='bold') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment