【集成学习】sklearn中xgboost模块中plot_importance函数(绘图--特征重要性)
直接上代码,简单
1 # -*- coding: utf-8 -*-
2 """
3 ###############################################################################
4 # 作者:wanglei5205
5 # 邮箱:wanglei5205@126.com
6 # 代码:http://github.com/wanglei5205
7 # 博客:http://cnblogs.com/wanglei5205
8 # 目的:学习xgboost的plot_importance函数
9 # 官方API文档:http://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.training
10 ###############################################################################
11 """
12 ### load module
13 import matplotlib.pyplot as plt
14 from sklearn import datasets
15 from sklearn.model_selection import train_test_split
16 from sklearn.metrics import accuracy_score
17 from xgboost import XGBClassifier
18 from xgboost import plot_importance
19
20 ### load datasets
21 digits = datasets.load_digits()
22
23 ### data analysis
24 print(digits.data.shape)
25 print(digits.target.shape)
26
27 ### data split
28 x_train,x_test,y_train,y_test = train_test_split(digits.data,
29 digits.target,
30 test_size = 0.3,
31 random_state = 33)
32
33 model = XGBClassifier()
34 model.fit(x_train,y_train)
35
36 ### plot feature importance
37 fig,ax = plt.subplots(figsize=(15,15))
38 plot_importance(model,
39 height=0.5,
40 ax=ax,
41 max_num_features=64)
42 plt.show()
43
44 ### make prediction for test data
45 y_pred = model.predict(x_test)
46
47 ### model evaluate
48 accuracy = accuracy_score(y_test,y_pred)
49 print("accuarcy: %.2f%%" % (accuracy*100.0))
50 """
51 95.0%
52 """
【集成学习】sklearn中xgboost模块中plot_importance函数(绘图--特征重要性)的更多相关文章
- 【集成学习】sklearn中xgboost模块的XGBClassifier函数
# 常规参数 booster gbtree 树模型做为基分类器(默认) gbliner 线性模型做为基分类器 silent silent=0时,不输出中间过程(默认) silent=1时,输出中间过程 ...
- sklearn中xgboost模块中plot_importance函数(特征重要性)
# -*- coding: utf-8 -*- """ ######################################################### ...
- 集成学习之Boosting —— XGBoost
集成学习之Boosting -- AdaBoost 集成学习之Boosting -- Gradient Boosting 集成学习之Boosting -- XGBoost Gradient Boost ...
- Lua中的模块与module函数详解
很快就要开始介绍Lua里的“面向对象”了,在此之前,我们先来了解一下Lua的模块. 1.编写一个简单的模块 Lua的模块是什么东西呢?通常我们可以理解为是一个table,这个table里有一些变量.一 ...
- EBS 中iSupplier模块中的MAPPING_ID
在EBS的供应商模块中,有一个非常有意思的表 POS_SUPPLIER_MAPPINGS, 这个表中建立了supplier_reg_id,vendor_id,party_id之间的映射关系. 这个表中 ...
- 由ffmpeg中avformat模块中的 URL_SCHEME_CHARS 看 strspn( ) 的妙用
在ffmpeg的avformat 模块中avio.c 对 URL_SCHEME_CHARS 的定义: #define URL_SCHEME_CHARS \ "abcdefghijklmnop ...
- python中datetime模块中datetime对象的使用方法
本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...
- python中threading模块中最重要的Tread类
Tread是threading模块中的重要类之一,可以使用它来创造线程.其具体使用方法是创建一个threading.Tread对象,在它的初始化函数中将需要调用的对象作为初始化参数传入. 具体代码如下 ...
- 第11.24节 Python 中re模块的其他函数
一. re.compile函数 正则表达式编译函数,在后面章节专门介绍. 二. re.escape(pattern) re.escape是一个工具函数,用于对字符串pattern中所有可能被视为正则表 ...
随机推荐
- redmine修改附件储存路径
如果想把redmine 1.x.x 版本中的attachments files 放在自定义的目录(例如/home/darkofday/redmineAttachFile/).执行下列命令:cd /ho ...
- 编译binutil包报错 error: array type has incomplete element type extern const struct relax_type md_relax_table[];
安装lfs时编译binutils出错: ../../sources/binutils-2.15.91.0.2/gas/config/tc-i386.h:457:32: error: array typ ...
- invocationCount和invocationTimeOut
这篇我们来学习下@Test中另外两个属性invocationCount和invocationTimeOut,前面我介绍了timOut这个属性,知道是超时监控的功能.同样,本篇两个属性和这个差不多,只不 ...
- [Vue]Vue语法糖v-bind、v-on
语法糖 :是指在不影响功能的情况下,添加某种方法实现同样的效果,从而方便程序开发,简化代码是书写. Vue.js的v-bind和v-on指令都提供了语法糖,也可以说是缩写. 1.v-bind可以省略, ...
- oracle实例内存(SGA和PGA)调整-xin
一.名词解释 (1)SGA:System Global Area是Oracle Instance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池.数据缓冲区.日志缓冲区. ( ...
- [转载]Java生成Word文档
在开发文档系统或办公系统的过程中,有时候我们需要导出word文档.在网上发现了一个用PageOffice生成word文件的功能,就将这块拿出来和大家分享. 生成word文件与我们编辑word文档本质上 ...
- python:使用itchat实现手机控制电脑
1.准备材料 首先电脑上需要安装了python,安装了opencv更好(非必需) 如果安装了opencv的话,在opencv的python目录下找到cv2.pyd,将该文件放到python的库搜索路径 ...
- 004-对象——public protected private PHP封装的实例
<?php /** *public protected private PHP封装的实例 */ /*class tv { private $shengyin; function __constr ...
- 【cf 483 div2 -C】Finite or not?(数论)
链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...
- 【Wannafly挑战赛9-A】找一找
链接:https://www.nowcoder.net/acm/contest/71/A 题目描述 给定n个正整数,请找出其中有多少个数x满足:在这n个数中存在数y=kx,其中k为大于1的整数 输入描 ...