直接上代码,简单

  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. 搭建时间服务器(linux)

    我们搭建集群环境的时候,时间必须是要统一的,才能保证集群数据的一致性. 一般操作是直接使用NTP,跟默认的时间服务器同步,但是最好还是让所有节点跟集群中的某台作为时间服务器的节点同步. 步骤:(节点有 ...

  2. LeetCode—— Partition Equal Subset Sum

    Question Given a non-empty array containing only positive integers, find if the array can be partiti ...

  3. 【医学图像】3D Deep Leaky Noisy-or Network 论文阅读(转)

    文章来源:https://blog.csdn.net/u013058162/article/details/80470426 3D Deep Leaky Noisy-or Network 论文阅读 原 ...

  4. LIS学习笔记(两种算法)O(n^2) 和 O(nlogn)

    2017-09-02 10:34:21 writer:pprp 最长上升子序列,具体分析看代码:O(n^2)的做法,dp的思想 分析:每次读一个进行扫描,如果当前读入的这个要比之前的大, 说明有可能加 ...

  5. [小问题笔记(七)] JS和 jQuery常用语句笔记(隐藏/显示/禁用标签 日期操作 跳转等)

    隐藏/显示标签 $("#div1").css("display", "none");$("#div2").css(&qu ...

  6. SQL优化- in和not in

    in不会导致索引失效,但最终数据库会将in语句解析为or语句,eg: select * from T_MAIN_PROCESS t where t.audit_status_code in ('05' ...

  7. DLL_Delphi动态调用

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

  8. Python绘图技巧

    转自:https://www.cnblogs.com/zhizhan/p/5615947.html Python--matplotlib绘图可视化知识点整理 强烈推荐ipython 原文:http:/ ...

  9. 三十二 Python分布式爬虫打造搜索引擎Scrapy精讲—scrapy的暂停与重启

    scrapy的每一个爬虫,暂停时可以记录暂停状态以及爬取了哪些url,重启时可以从暂停状态开始爬取过的URL不在爬取 实现暂停与重启记录状态 1.首先cd进入到scrapy项目里 2.在scrapy项 ...

  10. EASYUI 1.4版 combobox firefox 下不支持中文检索的问题

    easyui 的combobox 在IE下面输入中文,可以自动实现筛选和检索的功能,但是在firefox下面不可以. 于是查了一些资料,发现原来是浏览器对于中文输入法的处理问题,对于chrome 和 ...