Skip to content

Instantly share code, notes, and snippets.

@zero731
Created March 11, 2021 00:31
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 zero731/557f8e2392e82485e26df3c4a3e93225 to your computer and use it in GitHub Desktop.
Save zero731/557f8e2392e82485e26df3c4a3e93225 to your computer and use it in GitHub Desktop.
plot top 10 predictive features for example churn analysis
## 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