xgboost的sklearn接口和原生接口参数详细说明及调参指点
from xgboost import XGBClassifier
XGBClassifier(max_depth=3,learning_rate=0.1,n_estimators=100,silent=True,objective='binary:logistic',
booster='gbtree',n_jobs=1,nthread=None,gamma=0,min_child_weight=1, max_delta_step=0, subsample=1,
colsample_bytree=1, colsample_bylevel=1, reg_alpha=0, reg_lambda=1, scale_pos_weight=1, base_score=0.5, random_state=0,
seed=None, missing=None, **kwargs)
1.模型参数
max_depth:int |每个基本学习器树的最大深度,可以用来控制过拟合。典型值是3-10
learning_rate=0.1:
即是eta,为了防止过拟合,更新过程中用到的收缩步长,使得模型更加健壮。每次提升计算之后,算法会直接获得新特征的权重,eta通过缩减特征的权重使提升计算过程更加保守,缺省值为0.3 取值范围为:[0,1]。典型值一般设置为:0.01-0.2。
n_estimators=100,估计器的数量
silent:boolean|是否打印信息
objective:定义学习任务及相应的学习目标,可选目标函数如下:
“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
booster: default="gbtree",
可选gbtree和gblinear,gbtree使用基于树的模型进行提升计算,gblinear使用线性模型进行提升计算
n_jobs:线程数目
nthread:废弃
gamma:0,损失阈值,在树的一个叶节点上进行进一步分裂所需的最小损失减少量,越大,算法越保守。取值范围为:[0,∞]。在节点分裂时,只有分裂后损失函数的值下降了,才会分裂这个节点。Gamma指定了节点分裂所需的最小损失函数下降值。这个参数的值越大,算法越保守。这个参数的值和损失函数息息相关,所以是需要调整的。
min_child_weight=1,
拆分节点权重和阈值,如果节点的样本权重和小于该阈值,就不再进行拆分。在现行回归模型中,这个是指建立每个模型所需要的最小样本数。越大,算法越保守,可以用来减少过拟合。 取值范围为:[0,∞]
max_delta_step=0,
每棵树的最大权重估计。如果它的值被设置为0,意味着没有约束;如果它被设置为一个正值,它能够使得更新的步骤更加保守。通常这个参数是没有必要的,但是如果在逻辑回归中类别极其不平衡这时候他有可能会起到帮助作用。把它范围设置为1-10之间也许能控制更新。 取值范围为:[0,∞]
subsample=1,
随机选取一定比例的样本来训练树。设置为0.5,则意味着XGBoost将从整个样本集合中随机的抽取出50%子样本建立树模型,这能够防止过拟合。 取值范围为:(0,1]。典型值0.5-1
colsample_bytree=1,
选取构造树的特征比例。缺省值为1 取值范围为:(0,1] 。典型值0.5-1
colsample_bylevel=1,
Subsample ratio of columns for each split, in each level. 每个层分裂的节点数,这个一般很少用。用来控制树的每一级的每一次分裂,对列数的采样的占比。
reg_alpha=0,
L1 regularization term on weights,这个主要是用在数据维度很高的情况下,可以提高运行速度。
reg_lambda=1,
L2 regularization term on weights,这个其实用的很少
scale_pos_weight=1,
用来控制正负样本的比例,平衡正负样本权重,处理样本不平衡。在类别高度不平衡的情况下,将参数设置大于0,可以加快收敛。
base_score=0.5,
The initial prediction score of all instances, global bias.
random_state=0,
seed=None,废弃
missing=None,
在数据中,标注为缺失值的表示。如果为None,则默认为np.nan
**kwargs:
tree_method: string,[default=’auto’],xgboost构建树的算法,‘auto’,‘exact’,‘approx’,‘hist’
lambda_bias: 在偏置上的L2正则
sketch_eps: [default=0.03],只在approximate greedy algorithm上使用
updater: [default=’grow_colmaker,prune’],提供模块化的方式来构建树,一般不需要由用户设置
refresh_leaf: [default=1],刷新参数,如果为1,刷新叶子和树节点,否则只刷新树节点
process_type: [default=’default’],提升的方式
grow_policy: string [default=’depthwise’],控制新增节点的方式,‘depthwise’,分裂离根节点最近的节点,‘lossguide’,分裂损失函数变化最大的节点
max_leaves: [default=0],增加的最大节点数,只和lossguide’ grow policy相关
max_bins: [default=256],只和tree_method的‘hist’相关
调参关键参数:
xgboost的调参建议采用单参数调整的方法
过拟合控制参数:
直接控制模型的复杂度 |
max_depth, min_child_weight, gamma |
增大产生树的随机性 |
subsample, colsample_bytree eta, num_round |
处理不平衡的数据集 :
预测的排序(AUC) |
scale_pos_weight |
预测可靠性 |
max_delta_step |
判断过拟合的一般方法:
clf = xgb.XGBClassifier()
clf.fit(X_train,y_train,eval_set=[(X_train, y_train),(X_test, y_test)],eval_metric='logloss', verbose=True) #'validation_0':(X_train, y_train),'validation_1':(X_test, y_test) evals_result = clf.evals_result()
#{'validation_0': {'logloss': ['0.604835', '0.531479']},
# 'validation_1': {'logloss': ['0.41965', '0.17686']}}
xgboost如何判断特征重要性:
weight - 该特征在所有树中被用作分割样本的特征的次数;
gain - 在所有树中的平均增益;
cover - the average coverage of the feature when it is used in trees。
https://blog.csdn.net/lz_peter/article/details/85010931
2.方法列表
fit(X,y,sample_weight=None,eval_set=None,eval_metric=None,early_stopping_rounds=None,verbose=True, xgb_model=None, sample_weight_eval_set=None, callbacks=None)
sample_weight:每个样本的权重,设置方法:sample_weight=np.where(y==1,len(y)-sum(y),sum(y))
eval_set=None,A list of (X, y)
用作提早停止的验证集
eval_metric=None,
[默认和objective相关],校验数据所需要的评价指标,不同的目标函数将会有缺省的评价指标(rmse for regression, and error for classification, mean average precision for ranking),用户可以添加多种评价指标,对于Python用户要以list传递参数对给程序,而不是map参数list参数不会覆盖 ,’eval_metric’的可选参数如下:
“rmse”: root mean square error,均方根误差
“logloss”: negative log-likelihood,对数似然
“error”: Binary classification error rate,二值误差率,计算方法为误分样本/总样本
“merror”: Multiclass classification error rate,多分类误差率,计算方法同上
“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.
early_stopping_rounds=None,int, optional
verbose=True,可视化
xgb_model=None,str
file name of stored xgb model or ‘Booster’ instance Xgb model to be loaded before training (allows training continuation).
sample_weight_eval_set=None,
callbacks=None,
predict(data, output_margin=False, ntree_limit=None, validate_features=True)
ntree_limit :int
Limit number of trees in the prediction; defaults to best_ntree_limit if defined (i.e. it has been trained with early stopping), otherwise 0 (use all trees).
predict_proba(data, ntree_limit=None, validate_features=True)
apply(X, ntree_limit=0)
Return the predicted leaf every tree for each sample.
array_like, shape=[n_samples, n_trees]
evals_result()
Return the evaluation results.
If eval_set is passed to the fit function, you can call evals_result()
to get evaluation results for all passed eval_sets. When eval_metric is also passed to the fit function, the evals_result will contain the eval_metrics passed to the fit function.
Return type:dictionary
案例:
- 1.xgboost提早停止的使用方法、loss的可视化设置的操作:https://blog.csdn.net/xuxiatian/article/details/62226480
- 2.xgboost画出决策树:https://blog.csdn.net/anshuai_aw1/article/details/82988494
- 3.xgboost自定义损失函数和评估函数:https://blog.csdn.net/hfzd24/article/details/76903927 https://blog.csdn.net/u010412858/article/details/80143984
- 4.xgboost参数调优教程的文章:https://blog.csdn.net/han_xiaoyang/article/details/52665396
https://blog.csdn.net/a1b2c3d4123456/article/details/52849091
非常好的原理解释https://blog.csdn.net/sb19931201/article/details/52557382
xgboost的sklearn接口和原生接口参数详细说明及调参指点的更多相关文章
- lightgbm的sklearn接口和原生接口参数详细说明及调参指点
class lightgbm.LGBMClassifier(boosting_type='gbdt', num_leaves=31, max_depth=-1, learning_rate=0.1, ...
- word2vec参数调整 及lda调参
一.word2vec调参 ./word2vec -train resultbig.txt -output vectors.bin -cbow 0 -size 200 -window 5 -neg ...
- DeepMind提出新型超参数最优化方法:性能超越手动调参和贝叶斯优化
DeepMind提出新型超参数最优化方法:性能超越手动调参和贝叶斯优化 2017年11月29日 06:40:37 机器之心V 阅读数 2183 版权声明:本文为博主原创文章,遵循CC 4.0 BY ...
- Xgboost的sklearn接口参数说明
from xgboost.sklearn import XGBClassifier model=XGBClassifier(base_score=0.5, booster='gbtree', cols ...
- python+pytest接口自动化(6)-请求参数格式的确定
我们在做接口测试之前,先需要根据接口文档或抓包接口数据,搞清楚被测接口的详细内容,其中就包含请求参数的编码格式,从而使用对应的参数格式发送请求.例如某个接口规定的请求主体的编码方式为 applicat ...
- android 学习随笔二十七(JNI:Java Native Interface,JAVA原生接口 )
JNI(Java Native Interface,JAVA原生接口) 使用JNI可以使Java代码和其他语言写的代码(如C/C++代码)进行交互. 问:为什么要进行交互? 首先,Java语言提供的类 ...
- 接口作为方法的参数或返回值——List接口
接口作为方法的参数或返回值,源码可知,List为一个接口,ArraryList是的它的实现类: 其中,addNames方法中,入参和返回值都List接口,入参是多态的,编译看左,运行看右(访问成员方法 ...
- 编写高质量代码改善C#程序的157个建议——建议43:让接口中的泛型参数支持协变
建议43:让接口中的泛型参数支持协变 除了上一建议中提到的使用泛型参数兼容接口不可变性外,还有一种办法是为接口中的泛型声明加上out关键字来支持协变,如下所示: interface ISalary&l ...
- Python+request 分模块存放接口,多接口共用参数URL、headers的抽离,添加日志打印等《三》
主要介绍内容如下: 1.分模块存放接口 2.多接口共用参数URL.headers的抽离为配置文件 3.添加日志打印 4.一个py文件运行所有所测的接口 如上介绍内容的作用: 1.分模块存放接口:方便多 ...
随机推荐
- 快速挂载iso文件到虚拟机系统
在vm软件菜单栏那里选择vm,再选择弹出菜单最下面的设置,如图,找到实体机上的iso文件,保存. 这时候,在虚拟机ls /dev会发现有一个cdrom,这个就是我们的iso文件,不过我们还需要把它挂载 ...
- Rendering on the Web
转自: https://developers.google.com/web/updates/2019/02/rendering-on-the-web Rendering on the Web Goog ...
- php创建桌面快捷方式实现方法
http://blog.csdn.net/fdipzone/article/details/50423613
- Day 37 视图、存储过程、触发器、函数、事物、锁
一 .存储过程 1 create view stu_view as select * from ren 视图:是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据 视图有 ...
- [转]MyBatis中resultType与resultMap区别
MyBatis中关于resultType和resultMap的具体区别如下: MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap.resu ...
- DNS压力测试
安装 queryperf cd /usr/local/src wget http://ftp.isc.org/isc/bind9/9.12.1/bind-9.12.1.tar.gz 编译querype ...
- Go RPC返回值
Go 语言RPC定义格式如下: func (t T) MethodName(argType T1, replyType T2) error 第一个参数是接收的参数,第二个参数是返回给客户端的参数,第二 ...
- HanLP分词命名实体提取详解
HanLP分词命名实体提取详解 分享一篇大神的关于hanlp分词命名实体提取的经验文章,文章中分享的内容略有一段时间(使用的hanlp版本比较老),最新一版的hanlp已经出来了,也可以去看看新版 ...
- Spring Boot基础知识
Spring Boot 是微服务中最好的 Java 框架. 我们建议你能够成为一名 Spring Boot 的专家. 问题一 Spring Boot.Spring MVC 和 Spring 有什么区别 ...
- Delphi:窗体的扩展样式GWL_EXSTYLE用于SetWindowLong
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_TRANSPARENT or WS_EX_ ...