【问题标题】:Plot gain, cover, weight for feature importance of XGBoost model绘制 XGBoost 模型的特征重要性的增益、覆盖率、权重
【发布时间】:2020-01-28 15:54:33
【问题描述】:

我有一个 XGBoost 模型 xgboost_model。绘制此 XGBoost 模型的特征重要性;

plot_importance(xgboost_model)
pyplot.show()

该图显示了 F 分数。但是,F 分数背后有一些重要指标,例如增益、覆盖率、权重。

如何分别绘制重要性指标增益、覆盖率和权重?

我正在使用 python 3.7

【问题讨论】:

    标签: python machine-learning plot xgboost


    【解决方案1】:

    您可以将不同的重要性类型传递给plot_importance

    fig, ax = plt.subplots(3,1,figsize=(14,30))
    
    nfeats = 15
    importance_types = ['weight', 'cover', 'gain']
    
    for i, imp_i in enumerate(importance_types):
        plot_importance(xgboost_model, ax=ax[i], max_num_features=nfeats
                        , importance_type=imp_i
                        , xlabel=imp_i)
    

    在上面的例子中,你可以构建一个subplot,里面有3个地块,每个地块对应plot_importance支持的三种类型。

    我在jupyter 中对此进行了测试。否则,你会打电话给plt.show()

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 2017-04-07
      • 2020-10-26
      • 2017-11-14
      • 2019-02-28
      • 2022-06-20
      • 2019-04-15
      • 2017-01-15
      相关资源
      最近更新 更多