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