cv 验证
This is how I have trained a xgboost classifier with a 5-fold cross-validation to optimize the F1 score using randomized search for hyperparameter optimization:
clf_xgb = xgb.XGBClassifier(objective = 'binary:logistic')
param_dist = {'n_estimators': stats.randint(150, 500),
'learning_rate': stats.uniform(0.01, 0.07),
'subsample': stats.uniform(0.3, 0.7),
'max_depth': [3, 4, 5, 6, 7, 8, 9],
'colsample_bytree': stats.uniform(0.5, 0.45),
'min_child_weight': [1, 2, 3]
}
clf = RandomizedSearchCV(clf_xgb, param_distributions = param_dist, n_iter = 25, scoring = 'f1', error_score = 0, verbose = 3, n_jobs = -1)
numFolds = 5
folds = cross_validation.KFold(n = len(X), shuffle = True, n_folds = numFolds)
estimators = []
results = np.zeros(len(X))
score = 0.0
for train_index, test_index in folds:
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
clf.fit(X_train, y_train)
estimators.append(clf.best_estimator_)
results[test_index] = clf.predict(X_test)
score += f1_score(y_test, results[test_index])
score /= numFolds
cv 验证的更多相关文章
- 人工智能(Machine Learning)—— 机器学习
https://blog.csdn.net/luyao_cxy/article/details/82383091 转载:https://blog.csdn.net/qq_27297393/articl ...
- Machine Learning in Action(1) K-近邻
机器学习分两大类,有监督学习(supervised learning)和无监督学习(unsupervised learning).有监督学习又可分两类:分类(classification.)和回归(r ...
- 怎么训练出一个NB的Prophet模型
上篇<神器の争>主要是介绍Prophet的特点以及prophet入门的一些注意事项,但离真正的实际运用还有段距离.本篇主要讲解实际运用中Prophet调参的主要步骤以及一些本人实际经验. ...
- 总结:Bias(偏差),Error(误差),Variance(方差)及CV(交叉验证)
犀利的开头 在机器学习中,我们用训练数据集去训练(学习)一个model(模型),通常的做法是定义一个Loss function(误差函数),通过将这个Loss(或者叫error)的最小化过程,来提高模 ...
- scikit-learn一般实例之一:绘制交叉验证预测
本实例展示怎样使用cross_val_predict来可视化预测错误: # coding:utf-8 from pylab import * from sklearn import datasets ...
- 国内外从事CV相关的企业
提示:本文为笔者原创,转载请注明出处:blog.csdn.net/carson2005 经常碰到朋友问我国内从事计算机视觉(CV)领域的公司的发展情况,产品情况,甚至找工作等问题,这里,我给出自己收集 ...
- Tomcat双向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端超安全通信
紧接着<Tomcat单向Https验证搭建,亲自实现与主流浏览器.Android/iOS移动客户端安全通信>,此处演示下更安全的双向Https认证的通信机制,为了清晰明了,以下进行单独描述 ...
- Tomcat单向Https验证搭建,亲自实现与主流浏览器、Android/iOS移动客户端安全通信
众所周知,iOS9已经开始在联网方面默认强制使用Https替换原来的Http请求了,虽然Http和Https各有各的优势,但是总得来说,到了现在这个安全的信息时代,开发者已经离不开Https了. 网上 ...
- ASP.NET MVC系列:添加模型的验证规则
首先,在模型类中引用 System.ComponentModel.DataAnnotations 命名空间;System.ComponentModel.DataAnnotations 命名空间提供定义 ...
随机推荐
- gulp 集成其他基于流的工具
1. 流.缓冲.vinyl 文件对象 gulp 的流是虚拟文件对象 包含的属性有 base 文件名 path 文件路径 content 缓冲.nodejs 流 2. gulp 集成 browserif ...
- ②SpringBoot之Web综合开发
Spring boot初级教程 :<SpringBoot入门教学篇①>,方便大家快速入门.了解实践Spring boot特性,本文介绍springBoot的web开发 web开发sprin ...
- Eclipse自动生成 get/set
步骤一:在声明的数据域中按Ctrl+1: 步骤二:点击最后一个选项Create getter and setter,在弹出的对话框中点击确定: 在介绍另外一个方法: 步骤一:声明完类的数据域之后,输入 ...
- C# 反射之SqlDatareader转换为Model实体.
虽说反射的效率比较低,但是在当今的时代,盛行的大数据,以及高并发的产生,硬件的产能正在逐渐的提升,所以我们可以用空间来换取时间.反射所消耗的那些性能问题其实在企业级开发而言也就无所谓了.二 : 反射得 ...
- install OS from usb
https://unetbootin.github.io/ https://rufus.akeo.ie/
- spring-aop + memcached 的简单实现
一般情况下,java程序取一条数据是直接从数据库中去取,当数据库达到一定的连接数时,就会处于排队等待状态,某些在一定时间内不会发生变化的数据,完全没必要每次都从数据库中去取,使用spring-aop ...
- Qt WebRTC demo
This is a very simple demonstration of how to stream from a native application to the browser using ...
- 【转】关于一个Jmeter interface testing的实例
目标:测试某个保险系统的费率接口 准备:a 请求方式:Http b 接口地址://10.1.1.223:9090/rulesEngine/executeRateRule.do Jmeter 设置: a ...
- Avro之二:入门demo
一.使用avro-maven插件为avsc文件生成对应的java类: 在项目的pom.xml中增加依赖及插件如下: <dependency> <groupId>org.apac ...
- Python类(一)-实例化一个类
#-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" class Person(): n = 123 #类变量 def __init_ ...