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. 使用C# 开始第一个QQ机器人

    本示例将会使用”嘤鹉学舌”这个小插件的实现来演示如何使用Newbe.Mahua实现第一个机器人插件. 插件功能 自动将发送者的消息回发给发送人,嘤鹉(Parrot,其实是说嘤嘤嘤怪)学舌. 开发环境要 ...

  2. mybatis使用拦截器显示sql,使用druid配置连接信息

    1.显示出sql内容: 新建2个类:MybatisInterceptor :拦截sql,并获得输出sql内容 package com.cpp.core.filter; import java.text ...

  3. “Device eth0 does not seem to be present”解决办法

    在KVM中克隆出新的CentOS虚拟机时,出现如下问题:# service network restartShutting down loopback insterface: [ OK ]Bringi ...

  4. vue+element ui 的tab 动态增减,切换时提示用户是否切换

    前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui  有一个 bug,这里记录一下如何实现.转载 ...

  5. Ubuntu Grub 配置跟新

    自从上了Grub2,就开始装逼了,配置不如以前方便了. 需要修改一些基本的配置如菜单超时之类的可以修改/etc/default/grub文件,然后使用update-grub来更新/boot/grub/ ...

  6. HBuilder开发App Step1——环境搭建,HelloMUI 以及真机调试

    No1. 必须搭建java环境 只需要最基础的java环境,也就是cmd下可以运行java和javac即可, 具体教程请自行百度,都会有很详细的教程,这里不重点介绍. No2. 下载安装HBuilde ...

  7. How to Grid Search Hyperparameters for Deep Learning Models in Python With Keras

    Hyperparameter optimization is a big part of deep learning. The reason is that neural networks are n ...

  8. Linux 线程调度与优先级

    [转] http://blog.chinaunix.net/uid-20788636-id-1841334.html http://blog.chinaunix.net/uid-20788636-id ...

  9. Vue 框架-10-搭建脚手架 CLI

    Vue 框架-10-搭建脚手架 CLI + 批处理快捷启动 脚手架是通过 webpack 搭建的开发环境 使用 ES6 语法 打包和压缩 JS 为一个文件 项目文件在环境中,而不是浏览器 实现页面自动 ...

  10. python汉字转拼音

    上代码: #!/usr/bin/env python # -*- coding:utf-8 -*- """ Author:cleverdeng E-mail:clverd ...