xgboost 实践
xgboost 安装:xgboost:Scalable and Flexible Gradient Boosting
github:
eXtreme Gradient Boosting
中文教程:可伸缩且灵活的梯度提升
xgboost 用C++编写,提供了Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Flink and DataFlow 等接口
在python中的一套使用流程: python 平台下实现 xgboost 算法及输出的解释
参数意义:(先整理一下,实践中再完善) 官网的参数解释: XGBoost Parameters
XGBoost 参数
在运行 XGboost 之前,必须设置三种类型成熟:general parameters,booster parameters 和 task parameters:
- General parameters:参数控制在提升(boosting)过程中使用哪种 booster,常用的 booster 有树模型(tree)和线性模型(linear model)。
- Booster parameters:这取决于使用哪种 booster。
- Task parameters:控制学习的场景,例如在回归问题中会使用不同的参数控制排序。
- 除了以上参数还可能有其它参数,在命令行中使用
Parameters in R Package
In R-package, you can use .(dot) to replace under score in the parameters, for example, you can use max.depth as max_depth. The underscore parameters are also valid in R.
General Parameters
- booster [default=gbtree]
- 有两中模型可以选择 gbtree 和 gblinear。gbtree 使用基于树的模型进行提升计算,gblinear 使用线性模型进行提升计算。
缺省值为gbtree
- 有两中模型可以选择 gbtree 和 gblinear。gbtree 使用基于树的模型进行提升计算,gblinear 使用线性模型进行提升计算。
- silent [default=0]
- 取 0 时表示打印出运行时信息,取 1 时表示以缄默方式运行,不打印运行时信息。
缺省值为0
- 取 0 时表示打印出运行时信息,取 1 时表示以缄默方式运行,不打印运行时信息。
- nthread [default to maximum number of threads available if not set]
- XGBoost 运行时的线程数。
缺省值是当前系统可以获得的最大线程数
- XGBoost 运行时的线程数。
- num_pbuffer [set automatically by xgboost, no need to be set by user]
- size of prediction buffer, normally set to number of training instances. The buffers are used to save the prediction results of last boosting step.
- num_feature [set automatically by xgboost, no need to be set by user]
- boosting 过程中用到的特征维数,设置为特征个数。
XGBoost会自动设置,不需要手工设置
- boosting 过程中用到的特征维数,设置为特征个数。
Booster Parameters
From xgboost-unity, the bst: prefix is no longer needed for booster parameters. Parameter with or without bst: prefix will be equivalent(i.e. both bst:eta and eta will be valid parameter setting) .
Parameter for Tree Booster
- eta [default=0.3]
- 为了防止过拟合,更新过程中用到的收缩步长。在每次提升计算之后,算法会直接获得新特征的权重。 eta 通过缩减特征的权重使提升计算过程更加保守。
缺省值为0.3 - 取值范围为:[0,1]
- 为了防止过拟合,更新过程中用到的收缩步长。在每次提升计算之后,算法会直接获得新特征的权重。 eta 通过缩减特征的权重使提升计算过程更加保守。
- gamma [default=0]
- minimum loss reduction required to make a further partition on a leaf node of the tree. the larger, the more conservative the algorithm will be.
- range: [0,∞]
- max_depth [default=6]
- 数的最大深度。
缺省值为6 - 取值范围为:[1,∞]
- 数的最大深度。
- min_child_weight [default=1]
- 孩子节点中最小的样本权重和。如果一个叶子节点的样本权重和小于 min_child_weight 则拆分过程结束。在现行回归模型中,这个参数是指建立每个模型所需要的最小样本数。该成熟越大算法越 conservative
- 取值范围为: [0,∞]
- max_delta_step [default=0]
- Maximum delta step we allow each tree’s weight estimation to be. If the value is set to 0, it means there is no constraint. If it is set to a positive value, it can help making the update step more conservative. Usually this parameter is not needed, but it might help in logistic regression when class is extremely imbalanced. Set it to value of 1-10 might help control the update
- 取值范围为:[0,∞]
- subsample [default=1]
- 用于训练模型的子样本占整个样本集合的比例。如果设置为 0.5 则意味着 XGBoost 将随机的冲整个样本集合中随机的抽取出 50% 的子样本建立树模型,这能够防止过拟合。
- 取值范围为:(0,1]
- colsample_bytree [default=1]
- 在建立树时对特征采样的比例。
缺省值为1 - 取值范围:(0,1]
- 在建立树时对特征采样的比例。
Parameter for Linear Booster
- lambda [default=0]
- L2 正则的惩罚系数
- alpha [default=0]
- L1 正则的惩罚系数
- lambda_bias
- 在偏置上的 L2 正则。
缺省值为0(在 L1 上没有偏置项的正则,因为 L1 时偏置不重要)
- 在偏置上的 L2 正则。
Task Parameters
- objective [default=reg:linear]
- 定义学习任务及相应的学习目标,可选的目标函数如下:
- “reg:linear” –线性回归。
- “reg:logistic” –逻辑回归。
- “binary:logistic” –二分类的逻辑回归问题,输出为概率。
- “binary:logitraw” –二分类的逻辑回归问题,输出的结果为 wTx。
- “count:poisson” –计数问题的 poisson 回归,输出结果为 poisson 分布。
- 在 poisson 回归中,max_delta_step 的缺省值为 0.7。(used to safeguard optimization)
- “multi:softmax” –让 XGBoost 采用 softmax 目标函数处理多分类问题,同时需要设置参数 num_class(类别个数)
- “multi:softprob” –和 softmax 一样,但是输出的是 ndata * nclass 的向量,可以将该向量 reshape 成 ndata 行 nclass 列的矩阵。没行数据表示样本所属于每个类别的概率。
- “rank:pairwise” –set XGBoost to do ranking task by minimizing the pairwise loss
- base_score [default=0.5]
- the initial prediction score of all instances, global bias
- eval_metric [default according to objective]
- 校验数据所需要的评价指标,不同的目标函数将会有缺省的评价指标(rmse for regression, and error for classification, mean average precision for ranking)
- 用户可以添加多种评价指标,对于 Python 用户要以 list 传递参数对给程序,而不是 map 参数 list 参数不会覆盖’eval_metric’
- The choices are listed below:
- “rmse”: root mean square error
- “logloss”: negative log-likelihood
- “error”: Binary classification error rate. It is calculated as #(wrong cases)/#(all cases). For the predictions, the evaluation will regard the instances with prediction value larger than 0.5 as positive instances, and the others as negative instances.
- “merror”: Multiclass classification error rate. It is calculated as #(wrong cases)/#(all cases).
- “mlogloss”: Multiclass logloss
- “auc”: Area under the curve for ranking evaluation.
- “ndcg”:Normalized Discounted Cumulative Gain
- “map”:Mean average precision
- “ndcg@n”,”map@n”: n can be assigned as an integer to cut off the top positions in the lists for evaluation.
- “ndcg-“,”map-“,”ndcg@n-“,”map@n-“: In XGBoost, NDCG and MAP will evaluate the score of a list without any positive samples as 1. By adding “-” in the evaluation metric XGBoost will evaluate these score as 0 to be consistent under some conditions.
training repeatively
- seed [default=0]
- 随机数的种子。
缺省值为0
- 随机数的种子。
Console Parameters
The following parameters are only used in the console version of xgboost
* use_buffer [default=1]
- 是否为输入创建二进制的缓存文件,缓存文件可以加速计算。缺省值为1
* num_round
- boosting 迭代计算次数。
* data
- 输入数据的路径
* test:data
- 测试数据的路径
* save_period [default=0]
- 保存模型的时间段,设置 save_period = 10 意味着每 10 轮 XGBoost 将保存模型,将其设置为 0 意味着在训练期间不保存任何模型。
* task [default=train] options: train, pred, eval, dump
- train:训练明显
- pred:对测试数据进行预测
- eval:通过 eval[name]=filenam 定义评价指标
- dump:将学习模型保存成文本格式
* model_in [default=NULL]
- 指向模型的路径在 test, eval, dump 都会用到,如果在 training 中定义 XGBoost 将会接着输入模型继续训练
* model_out [default=NULL]
- 训练完成后模型的保持路径,如果没有定义则会输出类似 0003.model 这样的结果,0003 是第三次训练的模型结果。
* model_dir [default=models]
- 输出模型所保存的路径。
* fmap
- feature map, used for dump model
* name_dump [default=dump.txt]
- name of model dump file
* name_pred [default=pred.txt]
- 预测结果文件
* pred_margin [default=0]
- 输出预测的边界,而不是转换后的概率
xgboost 实践的更多相关文章
- 【sklearn】Toy datasets上的分类/回归问题 (XGBoost实践)
分类问题 1. 手写数字识别问题 from sklearn.datasets import load_digits digits = load_digits() # 加载手写字符识别数据集 X = d ...
- 【新人赛】阿里云恶意程序检测 -- 实践记录11.10 - XGBoost学习 / 代码阅读、调参经验总结
XGBoost学习: 集成学习将多个弱学习器结合起来,优势互补,可以达到强学习器的效果.要想得到最好的集成效果,这些弱学习器应当"好而不同". 根据个体学习器的生成方法,集成学习方 ...
- 机器学习之路: python 实践 提升树 XGBoost 分类器
git: https://github.com/linyi0604/MachineLearning 数据集被我下载到本地,可以去我的git上拿数据集 XGBoost提升分类器 属于集成学习模型 把成百 ...
- 【新人赛】阿里云恶意程序检测 -- 实践记录 11.24 - word2vec模型 + xgboost
使用word2vec训练词向量 使用word2vec无监督学习训练词向量,输入的是训练数据和测试数据,输出的是每个词的词向量,总共三百个词左右. 求和:然后再将每行数据中的每个词的词向量加和,得到每行 ...
- xgboost原理及应用
1.背景 关于xgboost的原理网络上的资源很少,大多数还停留在应用层面,本文通过学习陈天奇博士的PPT 地址和xgboost导读和实战 地址,希望对xgboost原理进行深入理解. 2.xgboo ...
- 【转】XGBoost参数调优完全指南(附Python代码)
xgboost入门非常经典的材料,虽然读起来比较吃力,但是会有很大的帮助: 英文原文链接:https://www.analyticsvidhya.com/blog/2016/03/complete-g ...
- 机器学习(四)--- 从gbdt到xgboost
gbdt(又称Gradient Boosted Decision Tree/Grdient Boosted Regression Tree),是一种迭代的决策树算法,该算法由多个决策树组成.它最早见于 ...
- 小巧玲珑:机器学习届快刀XGBoost的介绍和使用
欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:张萌 序言 XGBoost效率很高,在Kaggle等诸多比赛中使用广泛,并且取得了不少好成绩.为了让公司的算法工程师,可以更加方便的 ...
- XGBoost、LightGBM的详细对比介绍
sklearn集成方法 集成方法的目的是结合一些基于某些算法训练得到的基学习器来改进其泛化能力和鲁棒性(相对单个的基学习器而言)主流的两种做法分别是: bagging 基本思想 独立的训练一些基学习器 ...
随机推荐
- MT【85】正整数系数
评:这类与正整数有关的题,是很多学生所不习惯以及无从下手的.事实上很多时候要用到整数的这个性质:$m>n,m,n\in Z$则$m\ge n+1$,这道题用二次函数区间上有根的一般做法也可以,大 ...
- 洛谷U19464 山村游历(Wander)(LCT)
洛谷题目传送门 LCT维护子树信息常见套路详见我的总结 闲话 题目摘自WC模拟试题(by Philipsweng),原题目名Wander,"山村游历"是自己搞出来的中文名. 数据自 ...
- 数位dp——奏响数字数位的美妙乐章
数位dp:处理数字数位关系的一种dp方式. 一般的题目特征十分明显: 1.一般和数字本身有很大关系. 2.一般求数字在区间L,R中的一些信息 3.L,R一般很大,通常能达到long long级别. d ...
- 各种蕴含算法思想的DP - 2
study from: https://www.cnblogs.com/flashhu/p/9480669.html 3.斜率dp study from:http://www.cnblogs.com/ ...
- python爬虫 scrapy3_ 安装指南
安装指南 安装Scrapy 注解 请先阅读 平台安装指南. 下列的安装步骤假定您已经安装好下列程序: Python 2.7 Python Package: pip and setuptools. ...
- C语言复习---比赛问题
一:比赛问题 两个乒乓球队进行比赛,各出三人.甲队为a,b,c三人,乙队为x,y,z三人.已抽签决定比赛名单.有人向队员打听比赛的名单.a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单. ...
- jQuery下ajax事件的简单分析
昨天写了一篇关于监视页面动态生成元素问题的文章,引起了一些小小的争议,不过我从中学到了很多.文章在这,<jQuery下实现等待指定元素加载完毕>当然 动态生成的节点元素 分很多种情况,这里 ...
- ASP.Net巧用窗体母版页
背景:每个网页的基本框架结构类似: 浏览网站的时候会发现,好多网站中,每个网页的基本框架都是一样的,比如,最上面都是网站的标题,中间是内容,最下面是网站的版权.开发提供商等信息: 在这些网页中,表头. ...
- 五个案例让你明白GCD死锁(转)
转自:http://ios.jobbole.com/82622/ 死锁一直都是在使用多线程时,需要注意的一个问题.以前对同步.异步,串行.并行只有一个模糊的概念,想想也是时候整理一下了.再看看之前的博 ...
- 编写安全的API接口
HTTPS接口参数加密签名设计思路 数名 类型 必选 描述 _appid string 是 调用方身份ID,接口提供方用此来识别调不同的调用者,该参数是API基本规范的一部分,请详见API公共规范. ...