#coding=utf8

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction import DictVectorizer
from xgboost import XGBClassifier
titanic = pd.read_csv('./DataSets/Titanic/train.csv')
X = titanic[['Pclass', 'Age', 'Sex']]
y = titanic['Survived']
X['Age'].fillna(X['Age'].mean(), inplace=True)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=33)
vec = DictVectorizer(separator=False)
X_train = vec.fit_transform(X_train.to_dict(orient='record'))
#print X_train.to_dict(orient='record')
X_test = vec.transform(X_test.to_dict(orient='record'))
xgbc = XGBClassifier()
xgbc.fit(X_train, y_train)
print 'The accuracy of eXtreme Gradient Boosting Classifier on testing set:', xgbc.score(X_test, y_test)

#coding=utf8

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction import DictVectorizer
from xgboost import XGBClassifier
from sklearn.model_selection import GridSearchCV
titanic = pd.read_csv('./DataSets/Titanic/train.csv')
X = titanic[['Pclass', 'Age', 'Sex']]
y = titanic['Survived']

X['Age'].fillna(X['Age'].mean(), inplace=True)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=33)
vec = DictVectorizer(separator=False)
X_train = vec.fit_transform(X_train.to_dict(orient='record'))
#print X_train.to_dict(orient='record')
X_test = vec.transform(X_test.to_dict(orient='record'))
xgbc = XGBClassifier()

params = {'max_depth':range(2, 7), 'n_estimators':range(100, 1100, 200), 'learning_rate':[0.05, 0.1, 0.25, 0.5, 1.0]}
gs = GridSearchCV(xgbc, params, n_jobs=-1, cv=5, verbose=1)
gs.fit(X_train, y_train)
#print 'The accuracy of eXtreme Gradient Boosting Classifier on testing set:', gs.score(X_test, y_test)

print gs.best_score_
print gs.best_params_

xgboost 简单测试的更多相关文章

  1. TODO:Golang UDP连接简单测试慎用Deadline

    TODO:Golang UDP连接简单测试慎用Deadline UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interco ...

  2. .net orm比较之dapper和Entity Framework6的简单测试比较

    .net orm比较之dapper和Entity Framework6的简单测试比较

  3. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(37)-文章发布系统④-百万级数据和千万级数据简单测试 系列目录 我想测试EF在一百万条数据下的显示时间! ...

  4. ORACLE 数据库简单测试

    ORACLE 数据库简单测试 操作系统:Windows 7 – ORACLE:oracle database 10.2.0.4 一.目的 测试 启动监听程序.数据库  非同一个用户的情况,用户是否可以 ...

  5. Javascript的简单测试环境

    在<JavaScript忍者秘籍>2.4测试条件基础知识中,作者给出了一个精简版的assert和assert组的实现,对于初学者而言,这无疑是一个很好的例子,既让我们得到了一个好用的小工具 ...

  6. struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  7. struts2+hibernate+spring配置版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  8. [20190423]简单测试latch nowilling等待模式.txt

    [20190423]简单测试latch nowilling等待模式.txt --//我对这个问题的理解就是如果参数willing=0,表示无法获取该latch,直接退出,再寻找类似的latch.--/ ...

  9. Javascript学习-简单测试环境

    Javascript学习-简单测试环境 在<JavaScript忍者秘籍>2.4测试条件基础知识中,作者给出了一个精简版的assert和assert组的实现,对于初学者而言,这无疑是一个很 ...

随机推荐

  1. ORACLE 多表查询优化收集整理

    搞WEB的离不开数据库,在一个层面上,对数据库的熟练程度决定了很多的事情. 本文就大家都纠结的ORACLE多表查询的性能问题给出一系列个优化方法,那这些都是项目中长期用到的,所以很熟,很熟,已经成为习 ...

  2. CKEditor5 基本使用

    1.引入 <script type="text/javascript" src="/plugin/ckeditor5/ckeditor.js">&l ...

  3. 字符集(编码)转换_Linux

    ZC: 来自 我的项目 czgj 1.代码: #include <stdio.h> #include <iconv.h> #include <string.h> / ...

  4. [原][OSG]深入osg函数----SceneView::cull 函数

    参考:最长一帧 先介绍几个类: osgUtil::CullVisitor:“筛选访问器” 当我们使用它遍历场景图形的各个节点时, CullVisitor 将会对每一个遇到的节点执行场景筛选的工作,判断 ...

  5. linux上python安装相关

    [CentOS上安装python2.7和ipython]1,安装依赖库yum install readline-devel 2,按装python2.7和ipython //使用ipython需要先安装 ...

  6. Greengenes Database(16S)

    The Greengenes Database Release 13_5 这是16S的一个非常重要的数据库 The Greengenes Database, a public resource sin ...

  7. 绑定任意格式的XML文档到WPF的TreeView

    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...

  8. English trip -- Phonics 2 元音字母a

    xu言: 欲速则不达,如果这是你生命中最后一天.你还愿意花这么多精力继续坚持你现在做的事吗?如果答案是否定的,那么你需要改变了! What makes a word? 单词构成 Word 单词:    ...

  9. 【异常】redis.clients.jedis.exceptions.JedisDataException: ERR unknown command 'PSETEX'

    在spring中 针对 RedisTemplate类: private RedisTemplate<String, String> template; 当调用下面方法 template.o ...

  10. 浅谈musql中using的使用---高性能(三)

    转载地址:https://blog.csdn.net/lppl010_/article/details/79429657 mysql中using的用法为: using()用于两张表的join查询,要求 ...