简体   繁体   English

python 特征重要性条形图

[英]python feature importance bar chart

I have created my feature importance bar charts with the following code.我用以下代码创建了我的特征重要性条形图。 My question is how to label "Feature #" as the column name rather than feature 0, feature 1, etc. the first picture is what i made, the second picture is how i need it to look.我的问题是如何将 label “功能#”作为列名而不是功能 0、功能 1 等。第一张图片是我制作的,第二张图片是我需要它的外观。

for i,v in enumerate(importance):
print('Feature: %0d, Score: %.5f' % (i,v))
plt.bar([x for x in range(len(importance))], importance)
plt.show()

my created feature selection bar chart image我创建的特征选择条形图图像

how I want it to look image我希望它看起来如何

You can use set_xtickslabel method in order to specify the horizontal legend.您可以使用set_xtickslabel方法来指定水平图例。 In your case, something like在你的情况下,像

ax1 = plt.subplot()
plt.bar([x for x in range(len(importance))], importance)
ax1.set_xticklabels([f'Feature {X}' for X in range(len(importance))) 

Check here for more info在这里查看更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM