1.plot_importance方法

xgboost中的plot_importance方法内置了几种计算重要性的方式。

def plot_importance(booster, ax=None, height=0.2,xlim=None, ylim=None, title='Feature importance',xlabel='F score', ylabel='Features',importance_type='weight', max_num_features=None,grid=True, show_values=True, **kwargs):"""Plot importance based on fitted trees.Parameters----------booster : Booster, XGBModel or dictBooster or XGBModel instance, or dict taken by Booster.get_fscore()ax : matplotlib Axes, default NoneTarget axes instance. If None, new figure and axes will be created.grid : bool, Turn the axes grids on or off.  Default is True (On).importance_type : str, default "weight"How the importance is calculated: either "weight", "gain", or "cover"* "weight" is the number of times a feature appears in a tree* "gain" is the average gain of splits which use the feature* "cover" is the average coverage of splits which use the featurewhere coverage is defined as the number of samples affected by the splitmax_num_features : int, default NoneMaximum number of top features displayed on plot. If None, all features will be displayed.height : float, default 0.2Bar height, passed to ax.barh()xlim : tuple, default NoneTuple passed to axes.xlim()ylim : tuple, default NoneTuple passed to axes.ylim()title : str, default "Feature importance"Axes title. To disable, pass None.xlabel : str, default "F score"X axis title label. To disable, pass None.ylabel : str, default "Features"Y axis title label. To disable, pass None.show_values : bool, default TrueShow values on plot. To disable, pass False.kwargs :Other keywords passed to ax.barh()Returns-------ax : matplotlib Axes"""

plot_importance的方法签名如上所示。

从上面的方法签名可以看出
1.如果没有指定坐标轴名称,默认的x轴名称为"F score",y轴名称为"Features"。
2.重要性计算类型有三种,分别为weight, gain, cover,下面我们针对这三种计算类型进行总结。

2.weight

* "weight" is the number of times a feature appears in a tree

从上面的解释不难看出,weight方法衡量特征重要性的计算方式,是在子树进行分裂的时候,用到的特征次数,而且这里指的是所有的树。

一般来说,weight会给数值特征更高的值。因为连续值的变化越多,树分裂时候可以切割的空间就越大,那被用到的次数也就越多。所以对于weight指标,比较容易掩盖重要的枚举类特征。

3.gain

* "gain" is the average gain of splits which use the feature

gain采用的计算熵的方式。如果按某个特征进行分裂,熵的增量比较大,那么该特征的重要性就越强。
与特征选择里面采用计算信息增益的方式是一样的。

4.cover

* "cover" is the average coverage of splits which use the featurewhere coverage is defined as the number of samples affected by the split

cover的计算方法是,树在进行分列时,特征下面的叶子结点涵盖的样本数除以特征用来分裂的次数。当分裂越靠近树的根部时,cover的值会越大。

cover 对于枚举特征会更合适。同时,它也没有过度拟合目标函数,不会受目标函数的量纲影响。

5.permutation_importance方法

除此以外,还有permutation_importance方法也可以做衡量特征重要性的工作。sklearn官方文档针对该方法的说明如下

Permutation feature importance is a model inspection technique that can be used for any fitted estimator when the data is tabular.
This is especially useful for non-linear or opaque estimators.
The permutation feature importance is defined to be the decrease in a model score when a single feature value is randomly shuffled.
This procedure breaks the relationship between the feature and the target,
thus the drop in the model score is indicative of how much the model depends on the feature.
This technique benefits from being model agnostic and can be calculated many times with different permutations of the feature.

其原理大致如下:
1.首先根据训练集训练一个模型。
2.在测试集上测试该模型,得到模型相关的指标,比如回归问题为MSE,分类问题为logloss或者auc之类的指标。
3.在测试集上将某一个特征进行randomly shuffle(随机替换该特征值),在使用模型进行预测,得到新的模型指标。与第2步得到的指标进行比较,如果相差越多,说明特征的重要性越大。

Xgboost中特征重要性计算方法详解相关推荐

  1. XGBoost中特征重要性计算方法对比

    XGBoost作为比赛大杀器,内置了几种重要性函数,今天我们就在这篇文章中梳理三种常见的特征重要性计算方法,并思考他们的使用场景. xgboost.plot_importance(booster, a ...

  2. R语言中如何计算C-Statistics?几种计算方法详解

    R语言中如何计算C-Statistics?几种计算方法详解 目录 R语言中如何计算C-Statistics? #包导入 #数据加载编码

  3. xgboost和随机森林特征重要性计算方法

    随机森林中特征重要性和xgboost不同: 随机森林中的特征重要性主要是基于不纯度(也可以叫做Gini importance): 计算某一个节点不纯度为 其中,ωk\omega_kωk​,ωleft\ ...

  4. python xgboost参数_xgboost中XGBClassifier()参数详解

    常规参数 booster gbtree 树模型做为基分类器(默认) gbliner 线性模型做为基分类器 silent silent=0时,不输出中间过程(默认) silent=1时,输出中间过程 n ...

  5. [机器学习] 树模型(xgboost,lightgbm)特征重要性原理总结

    在使用GBDT.RF.Xgboost等树类模型建模时,往往可以通过 feature_importance 来返回特征重要性,各模型输出特征重要性的原理与方法 一 计算特征重要性方法 首先,目前计算特征 ...

  6. 尺度不变特征变换匹配算法详解

    尺度不变特征变换匹配算法详解 Scale Invariant Feature Transform(SIFT) Just For Fun 对于初学者,从David G.Lowe的论文到实现,有许多鸿沟, ...

  7. XGBoost输出特征重要性以及筛选特征

    XGBoost输出特征重要性以及筛选特征 1,梯度提升算法是如何计算特征重要性的? 使用梯度提升算法的好处是在提升树被创建后,可以相对直接地得到每个属性的重要性得分.一般来说,重要性分数,衡量了特征在 ...

  8. timm 视觉库中的 create_model 函数详解

    timm 视觉库中的 create_model 函数详解 最近一年 Vision Transformer 及其相关改进的工作层出不穷,在他们开源的代码中,大部分都用到了这样一个库:timm.各位炼丹师 ...

  9. 特征重要性计算方法及神经网络的特征重要性

    这是我第63篇文章.这篇文章主要简单讲一些常用特征重要性计算方法及神经网络的特征重要性计算方法. 1 几种常用的特征重要性计算方法 1.1 树模型特征重要性 像xgboost.lightgbm等树模型 ...

  10. Python计算向量夹角:向量夹角计算方法详解

    Python计算向量夹角:向量夹角计算方法详解 在数值分析和几何学中,我们经常需要计算两个向量之间的夹角.在Python中,我们可以使用numpy库中的函数来计算向量之间的夹角. 首先,我们需要将向量 ...

最新文章

  1. Ubuntu系统添加root用户
  2. java多线程中volatile关键字
  3. javax.cache_新的Java缓存标准(javax.cache)
  4. 1704:baoge的洗漱难题[黄]
  5. java操作mongodb(连接池)(转)
  6. android添加购物车动画、天气应用、渐变状态栏、文件选择器等源码
  7. 面试题目_数据分析之hive sql面试题目
  8. 克里金插值c程序_C罗游艇晒太阳,坐下也有六块腹肌,乔治娜骄傲秀无名指上鸽子蛋...
  9. Delphi 与 DirectX 之 DelphiX(15): TPictureCollectionItem.DrawWaveX、DrawWaveY ...
  10. ARCGIS空间自相关技术的实现
  11. 数据管理能力成熟度评估模型_什么是DCMM
  12. 电商api全境,Python网络爬虫与数据采集
  13. 使用 K8S 部署 RSS 全套自托管解决方案- RssHub + Tiny Tiny Rss
  14. 第一次养狗_如何度过艰难的第一个月
  15. 手机忘记开机密码怎么办?我来教你
  16. 家谱管理系统php,家谱管理系统(含源代码).docx
  17. photoSwipe插件使用
  18. 英飞凌硅麦焊接注意事项
  19. Messaging短信源码导入AndroidStudio
  20. delete数组报错

热门文章

  1. Confluence 6 附件存储提取文本文件
  2. expect自动登录以及远程脚本执行
  3. C语言printf语法
  4. 在Linux下使用命令发送邮件附件
  5. 10.React中的组件、父子组件、React props父组件给子组件传值、子组件给父组件传值、父组件中通过refs获取子组件属性和方法...
  6. python之Linux基础(三)
  7. mybatis操作mysql的奇淫技巧总结(代码库)
  8. singleTop对onActivityForResult的影响
  9. Java Session 会话技术
  10. [Windows编程] 开发DLL必读《Best Practices for Creating DLLs》