【问题标题】:How to list the respective column names when plotting feature importances?绘制特征重要性时如何列出相应的列名?
【发布时间】:2022-08-16 23:42:24
【问题描述】:

现在我有这个,将特征重要性列为数字,我怎样才能将列名放在 x 轴上?

importance = model.coef_[0]
for i,v in enumerate(importance):
print(\'Feature: %0d, Score: %.5f\' % (i,v))
plot feature importance
pyplot.bar([x for x in range(len(importance))], importance)
pyplot.show()

输出:

Feature: 0, Score: -0.11124
Feature: 1, Score: -0.04292
Feature: 2, Score: 0.00561

  • 使用sklearn?问题中缺少信息。问题中没有明显的功能名称,那么您在哪里可以找到它们?

标签: python pandas dataframe matplotlib


【解决方案1】:

在循环中使用pyplot.set_xlabel

pyplot.set_xlabel(xlabel=v)

【讨论】:

    猜你喜欢
    • 2017-11-14
    • 2021-11-13
    • 1970-01-01
    • 2017-12-14
    • 2020-06-04
    • 2022-06-20
    • 2019-11-05
    • 2020-11-13
    相关资源
    最近更新 更多