1.输出XGBoost特征的重要性

from matplotlib import pyplot
pyplot.bar(range(len(model_XGB.feature_importances_)), model_XGB.feature_importances_)
pyplot.show()

XGBoost 特征重要性绘图

也可以使用XGBoost内置的特征重要性绘图函数

# plot feature importance using built-in function
from xgboost import plot_importance
plot_importance(model_XGB)
pyplot.show()

XGBoost 内置的特征重要性绘图

2.根据特征重要性筛选特征

from numpy import sort
from sklearn.feature_selection import SelectFromModel # Fit model using each importance as a threshold
thresholds = sort(model_XGB.feature_importances_)
for thresh in thresholds:
# select features using threshold
selection = SelectFromModel(model_XGB, threshold=thresh, prefit=True)
select_X_train = selection.transform(X_train)
# train model
selection_model = XGBClassifier()
selection_model.fit(select_X_train, y_train)
# eval model
select_X_test = selection.transform(X_test)
y_pred = selection_model.predict(select_X_test)
predictions = [round(value) for value in y_pred]
accuracy = accuracy_score(y_test, predictions)
print("Thresh=%.3f, n=%d, Accuracy: %.2f%%" % (thresh, select_X_train.shape[1],
accuracy*100.0))

XGBoost 筛选特征

参考:https://blog.csdn.net/u011630575/article/details/79423162

XGBoost 输出特征重要性以及筛选特征的更多相关文章

  1. xgboost 特征重要性计算

    在XGBoost中提供了三种特征重要性的计算方法: ‘weight’ - the number of times a feature is used to split the data across ...

  2. 使用plot_importance绘制特征重要性曲线

    代码如下所示: # -*- coding: utf-8 -*- #导入需要的包 import matplotlib.pyplot as plt from sklearn import datasets ...

  3. kaggle数据挖掘竞赛初步--Titanic<随机森林&特征重要性>

    完整代码: https://github.com/cindycindyhi/kaggle-Titanic 特征工程系列: Titanic系列之原始数据分析和数据处理 Titanic系列之数据变换 Ti ...

  4. sklearn 可视化模型的训练测试收敛情况和特征重要性

    show the code: # Plot training deviance def plot_training_deviance(clf, n_estimators, X_test, y_test ...

  5. Spark连续特征转化成离散特征

    当数据量很大的时候,分类任务通常使用[离散特征+LR]集成[连续特征+xgboost],如果把连续特征加入到LR.决策树中,容易造成overfit. 如果想用上连续型特征,使用集成学习集成多种算法是一 ...

  6. OpenCV特征点检测------ORB特征

    OpenCV特征点检测------ORB特征 ORB是是ORiented Brief的简称.ORB的描述在下面文章中: Ethan Rublee and Vincent Rabaud and Kurt ...

  7. 处理离散型特征和连续型特征共存的情况 归一化 论述了对离散特征进行one-hot编码的意义

    转发:https://blog.csdn.net/lujiandong1/article/details/49448051 处理离散型特征和连续型特征并存的情况,如何做归一化.参考博客进行了总结:ht ...

  8. 图像的特征工程:HOG特征描述子的介绍

    介绍 在机器学习算法的世界里,特征工程是非常重要的.实际上,作为一名数据科学家,这是我最喜欢的方面之一!从现有特征中设计新特征并改进模型的性能,这就是我们进行最多实验的地方. 世界上一些顶级数据科学家 ...

  9. xgboost 特征选择,筛选特征的正要性

    import pandas as pd import xgboost as xgb import operator from matplotlib import pylab as plt def ce ...

随机推荐

  1. Redis configuration

    官方2.6配置如下: # Redis configuration file example # Note on units: when memory size is needed, it is pos ...

  2. 配置jenkins slave 问题,ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

    因为需要需要搭建一套自动化环境的windows电脑作为slave,简单的把原来用来mac上的job配置一模一样的配置了下,运行时遇到如上问题,google半天百思不得其解, 后来尝试把SCM里面的br ...

  3. Dubbo2.7源码分析-如何发布服务

    Dubbo的服务发布逻辑是比较复杂的,我还是以Dubbo自带的示例讲解,这样更方便和容易理解. Provider配置如下: <?xml version="1.0" encod ...

  4. asp后台读id设置样式

    加runat=“server”

  5. 【学习笔记】--- 老男孩学Python,day10, 函数, 动态参数 命名空间\作用域 global nonlocal

    1. 动态参数 位置参数的动态参数: *args 关键字参数的动态参数 : **kwargs 顺序:位置---*args---默认值---**kwargs 在形参上*聚合, **聚合 在实参上*打散, ...

  6. Tips——canvas闪屏问题的处理

    一.问题描述 在画canvas时,遇到屏幕瞬间空白的情况(大约1~2帧),造成用户体验不好. 二.原因 canvas的绘图过程是:先擦出整个画布:然后浏览器到达重绘时间点后,在空白的canvas上作画 ...

  7. java网络编程(TCP详解)

    网络编程详解-TCP 一,TCP协议的特点              面向连接的协议(有发送端就一定要有接收端)    通过三次连接握手建立连接 通过四次握手断开连接 基于IO流传输数据 传输数据大小 ...

  8. 关于vue跨域名对接微信授权认证和APP授权认证

    这种情况一般也只会出现在前后端分离,跨域名授权的时候吧.耗费了一个前端+一个后台+一个网关,熬夜通宵了两天才整出来一套方法(你们见过凌晨6点的杭州吗,对,我下班的时候天黑了,到家天亮了....),和开 ...

  9. opencv3.2.0形态学滤波之腐蚀

    /* 腐蚀(erode)含义: 腐蚀和膨胀是相反的一对操作,所以腐蚀就是求局部最小值的操作,腐蚀操作使原图中 国的高亮部分被腐蚀,效果图比原图有更小的高亮的区域. 腐蚀函数原型API及参数同膨胀相同 ...

  10. ArcGIS Server命令行工具学习笔记

    备份命令 backup.py 参数: -u 管理员账号 -p 密码 -s 站点URL -f 备份文件的存储目录路径 -h 显示帮助 还原命令 restore.py 参数: -u 管理员账号 -p 密码 ...