Skip to content

Instantly share code, notes, and snippets.

@vikramsoni2
Created October 3, 2018 09:46
Show Gist options
  • Save vikramsoni2/ae0b8888400320ebb20939123ce690a3 to your computer and use it in GitHub Desktop.
Save vikramsoni2/ae0b8888400320ebb20939123ce690a3 to your computer and use it in GitHub Desktop.
LGBMClassifier feature ranking
imp = pd.DataFrame({'feats':predictors,
'ranks': clf.feature_importances_}).sort_values('ranks', ascending=False)
fig, ax = plt.subplots(figsize=(12, 15))
# Example data
features = np.arange(len(imp.feats))
ranking = imp.ranks
ax.barh(features, ranking, align='center', color='skyblue', ecolor='black')
ax.set_yticks(features)
ax.set_yticklabels(imp.feats)
ax.invert_yaxis() # labels read top-to-bottom
ax.set_xlabel('Ranking')
ax.set_title('Featre importance')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment