【集成学习】sklearn中xgboost模块中plot_importance函数(绘图--特征重要性)

摘要:
直接上代码,简单1#-*-coding:utf-8-*-2"""3###############################################################################4#作者:wanglei52055#邮箱:wanglei5205@126.com6#代码:http://github.com/wanglei52057#博客:http://cn

直接上代码,简单

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函数(绘图--特征重要性)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇虚拟化之KVM的安装篇阿里巴巴Java开发手册(命名规范/常量定义篇)——查自己的漏-补自己的缺下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

.netcore在linux下使用P/invoke方式调用linux动态库

http://www.mamicode.com/info-detail-2358309.html   .netcore下已经实现了通过p/invoke方式调用linux的动态链接库(*.so)文件 1 [DllImport(@"libdl.so.2")] 2 public static extern IntPtr dlo...

python机器学习sklearn 岭回归(Ridge、RidgeCV)

  1、介绍     Ridge 回归通过对系数的大小施加惩罚来解决 普通最小二乘法 的一些问题。 岭系数最小化的是带罚项的残差平方和,          其中,α≥0α≥0 是控制系数收缩量的复杂性参数: αα 的值越大,收缩量越大,这样系数对共线性的鲁棒性也更强。        2、参数         alpha:{float,array-like}...

深度学习—1*1卷积核

主要作用: 1、跨通道的特征整合 2、特征通道的升维和降维 3、减少卷积核参数(简化模型),对于单通道feature map 用单核卷积即为乘以一个参数,而一般情况都是多核卷积多通道,实现多个feature map的线性组合 4、可以实现与全连接层等价的效果。如在faster-rcnn中用1*1*m的卷积核卷积n(如512)个特征图的每一个位置(像素点)...

如何基于 PHP-X 快速开发一个 PHP 扩展

0x01 起步 PHP-X本身基于C++11开发,使用cmake进行编译配置。首先,你需要确定所有依赖项已安装好。包括: gcc-4.8 或更高版本 PHP7.0 或更高版本,需要php7-dev 开发包 cmake-2.8 或更高版本 然后安装PHP-X。 git clone https://github.com/swoole/PHP-X.git c...

mybatis问题合集:#{}与${}区别、动态sql语句、缓存机制

一、MyBatis 中#{}和${}区别   #{} 是预编译处理,像传进来的数据会加个" "(#将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号)   ${} 就是字符串替换。直接替换掉占位符。$方式一般用于传入数据库对象,例如传入表名.   使用 ${} 的话会导致 sql 注入。什么是 SQL 注入呢?比如 select * from u...

mybatis教程:入门>>精通>>实战

以前曾经用过ibatis,这是mybatis的前身,当时在做项目时,感觉很不错,比hibernate灵活。性能也比hibernate好。而且也比较轻量级,因为当时在项目中,没来的及做很很多笔记。后来项目结束了,我也没写总结文档。已经过去好久了。但最近突然又对这个ORM 工具感兴趣。因为接下来自己的项目中很有可能采用这个ORM工具。所以在此重新温习了一下 m...