sklearn中xgboost模块中plot_importance函数(特征重要性)
# -*- coding: utf-8 -*-
"""
###############################################################################
# 作者:wanglei5205
# 邮箱:wanglei5205@126.com
# 代码:http://github.com/wanglei5205
# 博客:http://cnblogs.com/wanglei5205
# 目的:学习xgboost的plot_importance函数
# 官方API文档:http://xgboost.readthedocs.io/en/latest/python/python_api.html#module-xgboost.training
###############################################################################
"""
### load module
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from xgboost import XGBClassifier
from xgboost import plot_importance ### load datasets
digits = datasets.load_digits() ### data analysis
print(digits.data.shape)
print(digits.target.shape) ### data split
x_train,x_test,y_train,y_test = train_test_split(digits.data,
digits.target,
test_size = 0.3,
random_state = 33) model = XGBClassifier()
model.fit(x_train,y_train) ### plot feature importance
fig,ax = plt.subplots(figsize=(15,15))
plot_importance(model,
height=0.5,
ax=ax,
max_num_features=64)
plt.show() ### make prediction for test data
y_pred = model.predict(x_test) ### model evaluate
accuracy = accuracy_score(y_test,y_pred)
print("accuarcy: %.2f%%" % (accuracy*100.0))
"""
95.0%
"""
sklearn中xgboost模块中plot_importance函数(特征重要性)的更多相关文章
- 【集成学习】sklearn中xgboost模块中plot_importance函数(绘图--特征重要性)
直接上代码,简单 # -*- coding: utf-8 -*- """ ################################################ ...
- 【集成学习】sklearn中xgboost模块的XGBClassifier函数
# 常规参数 booster gbtree 树模型做为基分类器(默认) gbliner 线性模型做为基分类器 silent silent=0时,不输出中间过程(默认) silent=1时,输出中间过程 ...
- Lua中的模块与module函数详解
很快就要开始介绍Lua里的“面向对象”了,在此之前,我们先来了解一下Lua的模块. 1.编写一个简单的模块 Lua的模块是什么东西呢?通常我们可以理解为是一个table,这个table里有一些变量.一 ...
- 第11.24节 Python 中re模块的其他函数
一. re.compile函数 正则表达式编译函数,在后面章节专门介绍. 二. re.escape(pattern) re.escape是一个工具函数,用于对字符串pattern中所有可能被视为正则表 ...
- 由ffmpeg中avformat模块中的 URL_SCHEME_CHARS 看 strspn( ) 的妙用
在ffmpeg的avformat 模块中avio.c 对 URL_SCHEME_CHARS 的定义: #define URL_SCHEME_CHARS \ "abcdefghijklmnop ...
- python中threading模块中最重要的Tread类
Tread是threading模块中的重要类之一,可以使用它来创造线程.其具体使用方法是创建一个threading.Tread对象,在它的初始化函数中将需要调用的对象作为初始化参数传入. 具体代码如下 ...
- EBS 中iSupplier模块中的MAPPING_ID
在EBS的供应商模块中,有一个非常有意思的表 POS_SUPPLIER_MAPPINGS, 这个表中建立了supplier_reg_id,vendor_id,party_id之间的映射关系. 这个表中 ...
- python中datetime模块中datetime对象的使用方法
本文只讲述datetime模块中datetime对象的一些常用的方法,如果读者需要更多datetime模块的信息,请查阅此文档. datetime模块的对象有如下: timedelta date da ...
- 【集成学习】sklearn中xgboot模块中fit函数参数详解(fit model for train data)
参数解释,后续补上. # -*- coding: utf-8 -*- """ ############################################## ...
随机推荐
- static_cast, dynamic_cast, reinterpret_cast, const_cast的区别
static_cast最像C风格的强制转换,很多时候都需要程序员自身去判断转换是否安全.但是相对C风格的强制转换,在无关类的类指针之间转换上,有安全性的提升. dynamic_cast是运行时的转换吧 ...
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) E. Robot Arm 线段树
E. Robot Arm 题目连接: http://www.codeforces.com/contest/618/problem/E Description Roger is a robot. He ...
- NHibernate官方文档中文版--ISessionFactory的配置(ISessionFactory Configuration)
由于NHibernate是被设计应用在许多不同环境中的,因此它存在很多配置参数.幸运的是,这些参数大多都有合理的默认值,而且NHibernate发布的时候伴随着一个App.config 例子(可在sr ...
- 封装log4cp p
log4cpp 是参考 log4j 所写的 c++ 版本的写 log 的库.可以在这里下载 http://log4cpp.sourceforge.net/ 我的使用方法是: 1,定义了一个 _ ...
- OpenLayers2中的事件_以Popup为例
SATURDAY, 21 MARCH 1-Preface 前几天阅读学习了OpenLayers'Cookbook中的第四章——Working with events. 从AFDS系统的开发项目进行至今 ...
- ylbtech-LanguageSamples-NamedAndOptional(命名和可选参数)
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-NamedAndOptional(命名和可选参数) 1.A,示例(Sample) 返回顶 ...
- [转]Working with Transactions (EF6 Onwards)
本文转自:http://www.cnblogs.com/xiepeixing/p/5275999.html Working with Transactions (EF6 Onwards) This d ...
- yaha分词
yaha分词:https://github.com/jannson/yaha
- HTML5基础知识汇总_(2)自己定义属性及表单新特性
自己定义属性data-* 说起这个属性,事实上如今非经常见了;怎么说呢,由于在一些框架都能看到他的身影!!! 比方Jquery mobile,里面非常频繁的使用了这个属性; 这个属性是哪里来的-.当然 ...
- C# 深入理解堆栈、堆在内存中的实现
尽管在.NET framework下我们并不需要担心内存管理和垃圾回收(GarbageCollection),但是我们还是应该了解它们,以优化我们的应用程序.同时,还需要具备一些基础的内存管理工作机制 ...