Xgboost参数总结

参考链接

Xgboost官网参数介绍

1.简介

XGBoost一般包含三种类型的参数: 常规参数, 提升器参数任务参数.

  • 常规参数与我们用于提升的提升器有关,通常是树模型或线性模型
  • 提升器参数取决于你所选择的提升器
  • 学习任务的参数决定了学习场景, 例如回归任务可以使用不同的参数进行排序相关的任务
  • 命令行参数的行为与 xgboost 的 CLI 版本相关

2. 常规参数

  • booster [default=gbtree]

决定使用哪个booster,取值可以是gbtree、gblinear或dart。其中,gbtree和dart是基于树模型,gblinear是基于线性函数

  • silent [default=0]

是否打印运行信息。0表示打印,1表示不打印

  • nthread [default to maximum number of threads available if not set]

设置用于运行xgboost的并行线程数,默认为系统的最大线程数

  • num_pbuffer[xgboost自动设置,不需要用户设置]

预测结果所需的缓存大小,一般设置为训练样本数。缓存用来保存最后一轮提升的预测结果

  • num_feature[xgboost自动设置,不需要用户设置]

模型提升时使用的特征维度,一般设置为最大特征维度

3. 提升器参数

3.1 用于 Tree 提升的参数

  • eta [default=0.3]

迭代过程中为了避免过拟合而使用的步长。每次迭代后,我们都会获得各个特征的权重,而eta可以缩小这一权重而使得提升过程更鲁棒

取值范围: [0,1]

  • gamma [default=0]

节点分裂所需的最小损失下降值。该值越大,算法将会越保守

取值范围: [0,∞]

  • max_depth [default=6]

树的最大深度。该值越大,单棵树模型越复杂,越容易过拟合

取值范围: [1,∞]

  • min_child_weight [default=1]

叶节点样本的最小权重和。如果树的叶节点分裂使得叶节点的样本权重和小于该值,那么我们将停止分裂。该值越大,模型越保守,但容易欠拟合。

取值范围: [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

range: [0,∞]

  • subsample [default=1]

设置训练每棵树时采样的比例。如果设置为0.5,则表示每轮随机选取一半的样本用于训练。这可以降低过拟合

取值范围:(0.1]

  • colsample_bytree [default=1]

设置构建每棵树时随机选取特征的比例

取值范围:(0.1]

  • colsample_bylevel [default=1]

设置构建树时每一级每一次分裂随机选取特征的比例

取值范围:(0.1]

  • lambda [default=1]

权重的L2正则化项(类似于Ridge Regression)。该值增大将会使模型更保守

  • alpha [default=0]

权重的L1正则化项(类似于LASSO)。该值增大将会使模型更保守

  • tree_method, string [default=’auto’]

The tree constructtion algorithm used in XGBoost(see description in the reference paper)

Distributed and external memory version only support approximate algorithm.

Choices: {‘auto’, ‘exact’, ‘approx’}

‘auto’: Use heuristic to choose faster one.For small to medium dataset, exact greedy will be used. For very large-dataset, approximate algorithm will be choosed. Because old behavior is always use exact greedy in single machine, user will get a message when approximate algorithm is choosed to notify this choice.

‘exact’: Exact greedy algorithm.

‘approx’: Approximate greedy algorithm using sketching and histogram.

  • sketch_eps, [default=0.03]

This is only used for approximate greedy algorithm.

This roughly translated into O(1 / sketch_eps) number of bins. Compared to directly select number of bins, this comes with theoretical ganrantee with sketch accuracy.

Usuaully user do not have to tune this. but consider set to lower number for more accurate enumeration.
range: (0, 1)

  • scale_pos_weight, [default=0]

对于类别不平衡问题,可以设置该值来解决不平衡问题。该值常设置为负例样本数与正例样本数的比值

3.2 用于 Dart Booster 的其它参数

待补充

3.3 用于 Linear Booster 的参数

  • lambda [default=0]

权重的L2正则化项(类似于Ridge Regression)。该值增大将会使模型更保守

  • alpha [default=0]

权重的L1正则化项(类似于LASSO)。该值增大将会使模型更保守

  • lambda_bias

在偏置上的L2正则。缺省值为0(在L1上没有偏置项的正则,因为L1时偏置不重要)

4 学习任务的参数(定制学习任务及对应的学习目标)

  • objective [ default=reg:linear ]

可能的取值包括:

  1. “reg:linear” ----线性回归
  2. “reg:logistic” ----逻辑回归
  3. “binary:logistic” ----二分类的逻辑回归,输出的是概率
  4. “binary:logitraw” ----二分类的逻辑回归,输出的是逻辑回归方程中wTx(w的转置乘x)
  5. “count:poisson” ----poisson regression for count data, output mean of poisson distribution
    max_delta_step is set to 0.7 by default in poisson regression (used to safeguard optimization)
  6. “multi:softmax”----设置XGBoost使用softmax objective进行多分类。同时,你需要设置num_class
  7. “multi:softprob”----和softmax一样,但是输出的是ndata*nclass的向量,可以将该向量reshape成ndata行nclass列的矩阵。每行数据表示样本所属于每个类别的概率。
  8. “rank:pairwise”----set XGBoost to do ranking task by minimizing the pairwise loss
  9. “reg:gamma”----gamma regression for severity data, output mean of gamma distribution
  • base_score [ default=0.5 ]

the initial prediction score of all instances, global bias

如果迭代足够多次,改变该值将不会产生太大的影响

  • eval_metric [ default according to objective ]

设置验证集的评估指标。该参数的默认值根据目标函数而有所不同(回归时rmse;分类是error;ranking是平均准确率)

用户可以同时添加多个评估指标。python用户需要用列表类型传递多个评估指标

评估指标的取值包括:

  1. “rmse”: root mean square error
  2. “mae”: mean absolute error
  3. “logloss”: negative log-likelihood
  4. “error”: 二分类问题的分类错误率。对于预测问题,其预测值大于0.5的样本被认为是正例,小于0.5的认为是负例
  5. “merror”: 多分类问题的分类错误率,其取值为分类错误的样本数与总样本数的比值
  6. “mlogloss”: 多分类问题的logloss值
  7. “auc”: Area under the curve for ranking evaluation.
  8. “ndcg”:Normalized Discounted Cumulative Gain
  9. “map”:Mean average precision
  10. “ndcg@n”,”map@n”: n can be assigned as an integer to cut off the top positions in the lists for evaluation.
  11. “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
  12. “gamma-deviance”: [residual deviance for gamma regression]
  • seed [ default=0 ]

设置随机种子

5 命令行参数

下列参数需要在xgboost的控制版本中使用

  • use_buffer [ default=1 ]

设置是否将输入的文本创建为二进制的缓存文件。这样做将会减小加载时间

  • num_round

设置提升算法的迭代轮数

  • data

指定训练数据的路径

  • test:data

将要做预测的测试集的路径

  • save_period [default=0]

保存模型的迭代轮数。设置为10,表示每10轮保存模型;设置为0表示,表示训练过程不保存任何模型

  • task [default=train] options: train, pred, eval, dump
  1. train:使用训练数据训练
  2. pred:对测试数据进行预测
  3. eval:通过eval[name]=filenam定义评价指标
  4. dump:将学习模型保存成文本格式
  • model_in [default=NULL]

path to input model, needed for test, eval, dump, if it is specified in training, xgboost will continue training from the input model

  • model_out [default=NULL]

path to output model after training finishes, if not specified, will output like 0003.model where 0003 is number of rounds to do boosting.

  • 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]

predict margin instead of transformed probability

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 下面是一个使用贝叶斯优化来调整XGBoost参数的示例代码: ```python import xgboost as xgb from bayes_opt import BayesianOptimization # 定义优化目标函数 def xgb_cv(max_depth, learning_rate, n_estimators, gamma, min_child_weight, subsample, colsample_bytree): params = { 'eval_metric': 'rmse', 'max_depth': int(max_depth), 'learning_rate': learning_rate, 'n_estimators': int(n_estimators), 'gamma': gamma, 'min_child_weight': int(min_child_weight), 'subsample': subsample, 'colsample_bytree': colsample_bytree, 'n_jobs': -1, 'random_state': 42 } # 进行交叉验证 cv_result = xgb.cv(params, dtrain, num_boost_round=100, early_stopping_rounds=10, stratified=False) return -1.0 * cv_result['test-rmse-mean'].iloc[-1] # 定义参数范围 pbounds = {'max_depth': (3, 10), 'learning_rate': (0.01, 0.3), 'n_estimators': (50, 200), 'gamma': (0, 10), 'min_child_weight': (1, 10), 'subsample': (0.5, 1), 'colsample_bytree': (0.1, 1)} # 进行贝叶斯优化,找到最优超参数 optimizer = BayesianOptimization(f=xgb_cv, pbounds=pbounds, random_state=42) optimizer.maximize(init_points=5, n_iter=25) # 输出最优结果 print(optimizer.max) ``` 在上面的代码中,我们使用了XGBoost和贝叶斯优化的库。我们首先定义了一个优化的目标函数xgb_cv,它接受一些参数,构建XGBoost模型,并对模型进行交叉验证来计算目标值。然后我们定义了每个参数的范围,然后使用BayesianOptimization库来进行贝叶斯优化,找到最大化目标函数的最优参数组合。最后,我们输出了最优结果。 ### 回答2: 贝叶斯优化是一种用于超参数调优的统计方法,能够更高效地找到最优参数组合。在使用XGBoost算法时,也可以通过贝叶斯优化来搜索最佳的超参数组合。 首先,我们需要定义一个目标函数,用于评估不同超参数组合的性能。目标函数通常会根据给定超参数组合在训练集上进行交叉验证,并返回一个性能指标,如准确率或均方根误差。 接下来,我们需要定义超参数的搜索空间。对于XGBoost算法,常见的超参数包括学习率、树的深度、子采样比例等。贝叶斯优化通过在搜索空间内随机采样一些点,并利用高斯过程模型来建立超参数与性能指标之间的映射关系,进而根据这个模型预测下一个最有可能的超参数组合。 按照这个过程,我们可以进行多次迭代,每次得到一个新的超参数组合,并利用目标函数评估其性能。然后,我们将其加入贝叶斯优化的历史数据集中,并更新高斯过程模型,以便更准确地预测下一个最佳超参数组合。 最后,当迭代次数达到预设值或满足一定终止条件时,我们就可以得到一个在训练集上表现最好的超参数组合。 总结来说,贝叶斯优化在XGBoost参数调优中能够更高效地搜索最佳超参数组合。通过定义目标函数和搜索空间,并利用贝叶斯优化的方法迭代找到最佳超参数组合,可以显著提高XGBoost算法的性能。 ### 回答3: 贝叶斯优化是一种用于调整XGBoost模型的超参数的方法。XGBoost是一种强大的机器学习框架,但正确选择合适的超参数对模型性能至关重要。 首先,我们需要确定要调整的超参数。常见的超参数包括学习率、树的最大深度、叶子节点最小权重等。这些超参数的值将影响模型的准确性和复杂性。 接下来,我们使用贝叶斯优化方法来找到最佳的超参数组合。贝叶斯优化考虑了每次迭代的参数和结果之间的关联性。它建立了一个概率模型,并在每次迭代中根据先前的结果调整超参数来选择下一次迭代的参数。这允许我们在较少的迭代次数内找到最佳的超参数组合,从而节省时间和计算资源。 在选择下一组参数并进行训练之后,我们需要计算所得模型的性能指标,如准确率、精确率、召回率等。根据这些指标,我们可以确定当前超参数组合的性能,并将其与先前的结果进行比较。 接着,我们将优化过程迭代多次,直到找到最佳的超参数组合为止。通过使用贝叶斯优化方法,我们能够在较短时间内找到最优的超参数组合,提高模型的准确性和鲁棒性。 综上所述,贝叶斯优化是一种有效的方法来调整XGBoost模型的超参数。通过建立概率模型并根据先前的结果来选择下一个参数组合,贝叶斯优化能够帮助我们快速找到最佳的超参数组合,从而提高模型的性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值