直接上代码,简单

  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函数(绘图--特征重要性)的更多相关文章

  1. 【集成学习】sklearn中xgboost模块的XGBClassifier函数

    # 常规参数 booster gbtree 树模型做为基分类器(默认) gbliner 线性模型做为基分类器 silent silent=0时,不输出中间过程(默认) silent=1时,输出中间过程 ...

  2. sklearn中xgboost模块中plot_importance函数(特征重要性)

    # -*- coding: utf-8 -*- """ ######################################################### ...

  3. 集成学习之Boosting —— XGBoost

    集成学习之Boosting -- AdaBoost 集成学习之Boosting -- Gradient Boosting 集成学习之Boosting -- XGBoost Gradient Boost ...

  4. Lua中的模块与module函数详解

    很快就要开始介绍Lua里的“面向对象”了,在此之前,我们先来了解一下Lua的模块. 1.编写一个简单的模块 Lua的模块是什么东西呢?通常我们可以理解为是一个table,这个table里有一些变量.一 ...

  5. EBS 中iSupplier模块中的MAPPING_ID

    在EBS的供应商模块中,有一个非常有意思的表 POS_SUPPLIER_MAPPINGS, 这个表中建立了supplier_reg_id,vendor_id,party_id之间的映射关系. 这个表中 ...

  6. 由ffmpeg中avformat模块中的 URL_SCHEME_CHARS 看 strspn( ) 的妙用

    在ffmpeg的avformat 模块中avio.c 对 URL_SCHEME_CHARS 的定义: #define URL_SCHEME_CHARS \ "abcdefghijklmnop ...

  7. python中datetime模块中datetime对象的使用方法

    本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...

  8. python中threading模块中最重要的Tread类

    Tread是threading模块中的重要类之一,可以使用它来创造线程.其具体使用方法是创建一个threading.Tread对象,在它的初始化函数中将需要调用的对象作为初始化参数传入. 具体代码如下 ...

  9. 第11.24节 Python 中re模块的其他函数

    一. re.compile函数 正则表达式编译函数,在后面章节专门介绍. 二. re.escape(pattern) re.escape是一个工具函数,用于对字符串pattern中所有可能被视为正则表 ...

随机推荐

  1. struts2的refreshModelBeforeResult

    首先想介绍的是struts2的原型驱动ModelDriven机制. 所谓的ModelDriven,就是把一个实体类当成页面数据的收集对象.用法看起来像下面这个样子 <span style=&qu ...

  2. Spring Container的扩展点

    转自: http://blog.csdn.net/kkdelta/article/details/5488430 Spring在解析完配置文件后,会调用一些callback方法,使用Spring的开发 ...

  3. SSH 登录时出现如下错误:Host key verification failed

       注意:本文相关 Linux 配置及说明已在 CentOS 6.5 64 位操作系统中进行过测试.其它类型及版本操作系统配置可能有所差异,具体情况请参阅相应操作系统官方文档. 问题描述 使用 SS ...

  4. DLL_Delphi动态调用

    1.动态调用DLL unit formMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Co ...

  5. angular2 自定义双向绑定属性

    import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core'; @Component({ selecto ...

  6. pandas 运算

    Data frame 和 series 的运算:横列相加减:按照index ,row 的方向直接相加减.frame-series纵列相加减:按照 columns,运用算术函数,相加减. frame.s ...

  7. FontAwesome::Sass(5.x版)使用帮助。

    FontAwesome::Sass(5.x版) https://fontawesome.com/icons?d=gallery&m=free 只能使用免费的. 在app/assets/styl ...

  8. 【Demo】jQuery 轮播图简单动画效果

    功能实现: (1)设定图片称号的鼠标悬停事件: (2)在事件中利用自定义动画函数调整显示图片,并修改对应标号样式: (3)为图片显示区域设定鼠标悬停事件: (4)当鼠标停在该区域时,清除图片切换动画定 ...

  9. 二十五 Python分布式爬虫打造搜索引擎Scrapy精讲—Requests请求和Response响应介绍

    Requests请求 Requests请求就是我们在爬虫文件写的Requests()方法,也就是提交一个请求地址,Requests请求是我们自定义的 Requests()方法提交一个请求 参数: ur ...

  10. magento: Your web server is configured incorrectly. As a result, configuration files with sensitive information are accessible from the outside 解决方案

    在linux(以UBUNTU, CENTOS为例)下安装完成magento时,在进入后台时, 有些童鞋可能会发现有如下的提示: Your web server is configured incorr ...