增添:这篇博文讲的也特别好

正文:

Sk-learn作者的答案:

There are indeed several ways to get feature “importances”. As often, there is no strict consensus about what this word means.
In scikit-learn, we implement the importance as described in [1] (often cited, but unfortunately rarely read…). It is sometimes called “gini importance” or “mean decrease impurity” and is defined as the total decrease in node impurity (weighted by the probability of reaching that node (which is approximated by the proportion of samples reaching that node)) averaged over all trees of the ensemble.
In the literature or in some other packages, you can also find feature importances implemented as the “mean decrease accuracy”. Basically, the idea is to measure the decrease in accuracy on OOB data when you randomly permute the values for that feature. If the decrease is low, then the feature is not important, and vice-versa.
(Note that both algorithms are available in the randomForest R package.)
[1]: Breiman, Friedman, “Classification and regression trees”, 1984.

所以,共有两种比较流行的特征重要性评估方法:
这一篇文中有两种方法的代码:Selecting good features – Part III: random forests

  1. Mean decrease impurity
    这个方法的原理其实就是Tree-Model进行分类、回归的原理:特征越重要,对节点的纯度增加的效果越好。而纯度的判别标准有很多,如GINI、信息熵、信息熵增益。
    这也是Sklearn的feature_importances_的意义。
    代码:
from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor
import numpy as np
#Load boston housing dataset as an example
boston = load_boston()
X = boston["data"]
Y = boston["target"]
names = boston["feature_names"]
rf = RandomForestRegressor()
rf.fit(X, Y)
print "Features sorted by their score:"
print sorted(zip(map(lambda x: round(x, 4), rf.feature_importances_), names), reverse=True)
  1. Mean decrease accuracy
    这个方法更直观一些,是说某个特征对模型精度的影响。把一个变量的取值变为随机数,随机森林预测准确性的降低程度。该值越大表示该变量的重要性越大。
    这个方法是很多研究、文献中所采用的方法。
    代码:
from sklearn.cross_validation import ShuffleSplit
from sklearn.metrics import r2_score
from collections import defaultdictX = boston["data"]
Y = boston["target"]rf = RandomForestRegressor()
scores = defaultdict(list)#crossvalidate the scores on a number of different random splits of the data
for train_idx, test_idx in ShuffleSplit(len(X), 100, .3):X_train, X_test = X[train_idx], X[test_idx]Y_train, Y_test = Y[train_idx], Y[test_idx]r = rf.fit(X_train, Y_train)acc = r2_score(Y_test, rf.predict(X_test))for i in range(X.shape[1]):X_t = X_test.copy()np.random.shuffle(X_t[:, i])shuff_acc = r2_score(Y_test, rf.predict(X_t))scores[names[i]].append((acc-shuff_acc)/acc)
print "Features sorted by their score:"
print sorted([(round(np.mean(score), 4), feat) forfeat, score in scores.items()], reverse=True)

关于两个方法的比较,有一个人的回答是这样的:
the second metric actually gives you a direct measure of this, whereas the “mean decrease impurity” is just a good proxy.
使用Mean decrease accuracy是最直观的方法,使用Mean decrease impurity仅仅是Mean decrease accuracy一个比较好的“代理”。

sklearn的feature_importances_含义是什么?相关推荐

  1. 数据挖掘原理与算法:机器学习->{[sklearn. model_selection. train_test_split]、[h2o]、[网格搜索]、[numpy]、[plotly.express]}

    数据挖掘原理与算法:机器学习->{[sklearn. model_selection. train_test_split].[h2o].[网格搜索].[numpy].[plotly.expres ...

  2. 机器学习特征工程之特征选择

                                                                 前言 本文总结了特征选择的常用方法,并附上Python实现代码,其中输入数据集 ...

  3. Covariate Shift(协变量偏移)

    转载于https://zhuanlan.zhihu.com/p/205183444 此系列文章为笔者学习工作中的阶段性总结,难免有纰漏,如有不正之处,欢迎指正,大家共同成长. Covariate Sh ...

  4. Covariate Shift

    转载于https://zhuanlan.zhihu.com/p/205183444 此系列文章为笔者学习工作中的阶段性总结,难免有纰漏,如有不正之处,欢迎指正,大家共同成长. Covariate Sh ...

  5. LLE算法实现与sklearn实现

    在pyhton的机器学习库sklearn中,LLE等降维算法可以直接调用,在本次大作业中,根据LLE的推导过程编写算法实现了LLE,与mainfold自带的LLE进行对比.由于后面的实验中都是直接调用 ...

  6. 使用机器学习模型预测贷款资格

    介绍(Introduction) Loans are the core business of banks. The main profit comes directly from the loan' ...

  7. sklearn的train_test_split()各函数参数含义解释(非常全)

    sklearn的train_test_split()各函数参数含义解释(非常全) sklearn的train_test_split()各函数参数含义解释(非常全) - The-Chosen-One - ...

  8. sklearn之XGBModel:XGBModel之feature_importances_、plot_importance的简介、使用方法之详细攻略

    sklearn之XGBModel:XGBModel之feature_importances_.plot_importance的简介.使用方法之详细攻略 目录 feature_importances_ ...

  9. sklearn之train_test_split()函数各参数含义

    在机器学习中,我们通常将原始数据按照比例分割为"测试集"和"训练集",从 sklearn.model_selection 中调用train_test_split ...

最新文章

  1. 快讯 | 首期“医工结合系列研讨会”汇聚清华力量,共促医工融合发展
  2. 对分查找的最多次数_Java数据结构与算法:多路查找树
  3. 国货之光业务增长背后的技术支持 - 完美日记的云原生实践
  4. 10没有基于策略的qos_WebRTC QoS | NACK 格式与发送策略
  5. Ubuntu 21.04终端中文乱码和无法输入中文
  6. java jinternalframe_JInternalFrame的使用
  7. 关于eclipse项目红色感叹号的解决办法
  8. 除冰机行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
  9. 深入解析 ES6 系列(二)
  10. npm install 报错operation not permitted, unlink
  11. Nerwo(原npss)邀请链接
  12. bootdo 重命名 版本2.0 (适合所有springboot项目)
  13. 【百度地图2.5D、3D在Vue项目中的使用】嵌入二维百度地图、三维百度地图、多种显示模式风格样式颜色的百度地图
  14. STM32H7 DMA阅读笔记
  15. Windows10安装fiddler工具安装证书失败总结手机抓包总结
  16. 合并两个有序数组(给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组。)
  17. 令人敬畏的泰格伍兹 万维钢_5个令人敬畏的全新高级jQuery插件,2013年10月
  18. 分享到微信,qq空间,微博
  19. 测量误差(error)的概念
  20. 原创 全城公交标注系统 (2)

热门文章

  1. linux 虚拟网卡 源码,Linux的虚拟网卡TUN和TAP
  2. 【35. 多重背包】
  3. 《计算机软件测试规范》学习记录
  4. 黑莓手机与安卓机的对比
  5. ui设计培训费用是多少?
  6. 【Mac开发工具分享】菜鸟程序员高效开发的小秘密!
  7. c语言照样解决脑筋急转弯
  8. 《赤壁》学习笔记(一)
  9. uniapp-previewImage循环使用的一个小问题
  10. 第十一章 :日志采集工具flume使用