【问题标题】:Plot nlargest is showing the inverse outputPlot nlargest 显示反向输出
【发布时间】:2022-11-28 21:38:07
【问题描述】:

我正在尝试使用以下代码绘制使用随机森林算法生成的特征重要性。

但是,最大值显示在底部。但我希望他们处于领先地位。

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

您可以在下图中看到所有大值都在底部。但是,我希望它们出现在图表的顶部。

为什么输出以相反的顺序显示?

【问题讨论】:

    标签: python pandas matplotlib machine-learning plot


    【解决方案1】:

    您可以反转 y 轴:

    plt.gca().invert_yaxis()
    

    【讨论】:

      【解决方案2】:

      尝试这个。不知道这是否有效。

      feat_importances.sort(ascending=0).nlargest(20).plot(kind='barh')
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-31
        • 2016-10-25
        • 1970-01-01
        • 2013-08-25
        • 2013-07-23
        • 1970-01-01
        • 2017-02-16
        • 2017-09-18
        相关资源
        最近更新 更多