我有一个XGBoost模型 xgboost_model
。为了绘制这个XGBoost模型的特征重要性;
plot_importance(xgboost_model)pyplot.show()
该图表显示了F分数。然而,在F分数后面还有如增益、覆盖率、权重等重要性指标。
如何单独绘制增益、覆盖率、权重的重要性指标?
我使用的是Python 3.7
回答:
您可以将不同的重要性类型传递给 plot_importance
:
fig, ax = plt.subplots(3,1,figsize=(14,30))nfeats = 15importance_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)
在上面的例子中,您可以构建一个包含3个图表的subplot
,每个图表对应plot_importance
支持的三种类型之一。
我在jupyter
中测试了这个方法。否则,您需要调用plt.show()
。