Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Plot nlargest is showing the inverse output

I am trying to plot the feature importance generated using random forest algorithm using the below code.

However, the largest values are shown at the bottom. But I want them to be at the top.

feat_importances = pd.Series(g_search.best_estimator_.feature_importances_, index=X_train.columns)
feat_importances.nlargest(20).plot(kind='barh')

You can see the graph below that all large values are at the bottom. But, I want them to appear on top of the graph.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why is the output showing in reverse order?

enter image description here

>Solution :

You can reverse your y-axis:

plt.gca().invert_yaxis()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading