Xgboost 官方源码(python版本)

官网地址

一.XGBClassifier

xgboost.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)
Parameters
  • max_depth (int) – Maximum tree depth for base learners.
  • learning_rate (float) – Boosting learning rate (xgb’s “eta”)
  • n_estimators (int) – Number of boosted trees to fit.
  • silent (boolean) – Whether to print messages while running boosting.
  • objective (string) – Specify the learning task and the corresponding learning objective. Only “rank:pairwise” is supported currently.
  • booster (string) – Specify which booster to use: gbtree, gblinear or dart.
  • nthread (int) – Number of parallel threads used to run xgboost. (Deprecated, please use n_jobs)
  • n_jobs (int) – Number of parallel threads used to run xgboost. (replaces nthread)
  • gamma (float) – Minimum loss reduction required to make a further partition on a leaf node of the tree.
  • min_child_weight (int) – Minimum sum of instance weight(hessian) needed in a child.
  • max_delta_step (int) – Maximum delta step we allow each tree’s weight estimation to be.
  • subsample (float) – Subsample ratio of the training instance.
  • colsample_bytree (float) – Subsample ratio of columns when constructing each tree.
  • colsample_bylevel (float) – Subsample ratio of columns for each split, in each level.
  • reg_alpha (float (xgb's alpha)) – L1 regularization term on weights
  • reg_lambda (float (xgb's lambda)) – L2 regularization term on weights
  • scale_pos_weight (float) – Balancing of positive and negative weights.
  • base_score – The initial prediction score of all instances, global bias.
  • seed (int) – Random number seed. (Deprecated, please use random_state)
  • random_state (int) – Random number seed. (replaces seed)
  • missing (floatoptional) – Value in the data which needs to be present as a missing value. If None, defaults to np.nan.
  • **kwargs (dictoptional) –

    Keyword arguments for XGBoost Booster object. Full documentation of parameters can be found here: https://github.com/dmlc/xgboost/blob/master/doc/parameter.rst. Attempting to set a parameter via the constructor args and **kwargs dict simultaneously will result in a TypeError.

 

二.XGBRegressor

xgboost.XGBRegressor(max_depth=3,
                    learning_rate=0.1, 
                    n_estimators=100, 
                    silent=True, objective='reg:linear', 
                    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, 
                    importance_type='gain', 
                    **kwargs)
Parameters:
  • max_depth (int) – Maximum tree depth for base learners.
  • learning_rate (float) – Boosting learning rate (xgb’s “eta”)
  • n_estimators (int) – Number of boosted trees to fit.
  • silent (boolean) – Whether to print messages while running boosting.
  • objective (string or callable) – Specify the learning task and the corresponding learning objective or a custom objective function to be used (see note below).
  • booster (string) – Specify which booster to use: gbtree, gblinear or dart.
  • nthread (int) – Number of parallel threads used to run xgboost. (Deprecated, please use n_jobs)
  • n_jobs (int) – Number of parallel threads used to run xgboost. (replaces nthread)
  • gamma (float) – Minimum loss reduction required to make a further partition on a leaf node of the tree.
  • min_child_weight (int) – Minimum sum of instance weight(hessian) needed in a child.
  • max_delta_step (int) – Maximum delta step we allow each tree’s weight estimation to be.
  • subsample (float) – Subsample ratio of the training instance.
  • colsample_bytree (float) – Subsample ratio of columns when constructing each tree.
  • colsample_bylevel (float) – Subsample ratio of columns for each split, in each level.
  • reg_alpha (float (xgb's alpha)) – L1 regularization term on weights
  • reg_lambda (float (xgb's lambda)) – L2 regularization term on weights
  • scale_pos_weight (float) – Balancing of positive and negative weights.
  • base_score – The initial prediction score of all instances, global bias.
  • seed (int) – Random number seed. (Deprecated, please use random_state)
  • random_state (int) – Random number seed. (replaces seed)
  • missing (floatoptional) – Value in the data which needs to be present as a missing value. If None, defaults to np.nan.
  • importance_type (stringdefault "gain") – The feature importance type for the feature_importances_ property: either “gain”, “weight”, “cover”, “total_gain” or “total_cover”.
  • **kwargs (dictoptional) –

    Keyword arguments for XGBoost Booster object. Full documentation of parameters can be found here: https://github.com/dmlc/xgboost/blob/master/doc/parameter.rst. Attempting to set a parameter via the constructor args and **kwargs dict simultaneously will result in a TypeError.

 

 

 

 

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
XGBoost是一种基于梯度提升树(Gradient Boosting Tree)的机器学习算法,在Python中有相应的源码实现。下面是关于XGBoostPython源码实现的简要介绍。 PythonXGBoost实现是基于C++编写的,通过Python接口提供了方便的调用和使用方式。XGBoost使用了一种优化的并行策略,可以在大规模数据集上高效地训练模型。 首先,我们需要安装XGBoostPython包,在终端或命令提示符中使用pip install xgboost命令可以轻松安装。 然后,在Python中引入xgboost库,我们就可以使用其中提供的各种函数和类来构建和训练XGBoost模型。例如,可以使用xgboost模块下的XGBClassifier和XGBRegressor类来构建分类和回归模型。 XGBoostpython源码实现提供了许多参数来调整和优化模型的性能。我们可以设置树的深度(max_depth)、学习率(learning_rate)、迭代次数(n_estimators)等参数来适应不同的数据集和问题。 在使用XGBoost进行训练时,我们需要将输入数据转换为DMatrix对象,该对象是XGBoost特定的数据结构。接着,可以使用XGBClassifier或XGBRegressor的fit方法来训练模型。 除此之外,XGBoost还提供了诸如预测、特征重要性评估和保存模型等功能。我们可以使用训练好的模型对新样本进行预测,并通过调用XGBClassifier或XGBRegressor的predict方法来获得预测结果。 总而言之,XGBoostPython源码实现提供了一个强大且灵活的机器学习工具,可以高效地处理大规模数据集并获得优秀的预测性能。通过合理设置参数和使用适当的数据预处理方法,我们可以在不同的问题上使用XGBoost来进行分类和回归任务。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值