# XGBoost

**XGBoost**（eXtreme Gradient Boosting，极端梯度提升）是一个分布式梯度提升决策树库，以正则化的二阶目标函数训练回归树的加性集成。它由陈天奇（Tianqi Chen）和卡洛斯·格斯特林（Carlos Guestrin）在2016年KDD论文中提出，文中将其描述为一个可扩展的端到端树提升系统，并配有处理缺失数据的新型稀疏感知算法。<sup>[1](https://arxiv.org/abs/1603.02754)</sup> 该软件包支持加权分类与排序目标、用户自定义目标，并提供Python、R和Julia接口且与scikit-learn集成；其分布式版本构建于rabit库之上。<sup>[1](https://arxiv.org/abs/1603.02754)</sup> 它处于弗里德曼（Friedman）[梯度提升](https://www.edgepedia.org/zh/gradient-boosting)之后的提升算法谱系中，增添了正则化、二阶优化以及面向大数据的系统工程。

| 关键事实 | 详情 |
|---|---|
| 目标函数 | \( L(\phi) = \sum_i l(\hat{y}_i, y_i) + \sum_k \Omega(f_k) \)，其中 \( \Omega(f) = \gamma \cdot T + \tfrac{1}{2} \lambda \|w\|^2 \) 对叶节点数 \( T \) 和叶权重的L2范数施加惩罚<sup>[1](https://arxiv.org/abs/1603.02754)</sup> |
| 提升步骤 | 每轮 \( t \) 使用损失在当前位置的梯度 \( g_i \) 与海森 \( h_i \) 做二阶泰勒展开<sup>[1](https://arxiv.org/abs/1603.02754)</sup> |
| 树方法 | CPU上有exact、approx和hist三种；hist最快，因为它在训练前只做一次草图<sup>[2](https://xgboost.readthedocs.io/en/release_3.0.0/treemethod.html)</sup> |
| 缺失值 | 稀疏感知的默认方向：每次分裂同时测试左右两个方向并选取增益更优者，因此含NaN的数据可直接输入<sup>[3](https://xgboost.org/papers/chen-guestrin-2016-annotated/)</sup> |
| 关键默认值 | max_depth 6、eta 0.3、reg_lambda 1、min_child_weight 1、subsample 1、gamma 0<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup> |
| 竞赛战绩 | 2015年公布的29个Kaggle获胜方案中有17个使用了XGBoost；KDDCup 2015前十名队伍全部使用它<sup>[1](https://arxiv.org/abs/1603.02754)</sup> |
| 解释性 | 内置gain、weight和cover分数，并可通过shap包获得精确的Tree SHAP值<sup>[5](https://xgboost.org/concept/xgboost-feature-importance-methods/)</sup> |

## 算法原理

梯度提升构建加性模型：每棵新树纠正当前集成的误差。XGBoost的独特之处在于每轮所优化的目标。在第 \( t \) 轮，损失用二阶泰勒展开近似，

\[ L^{(t)} \approx \sum_{i=1}^{n} \left[ l(y_i, \hat{y}^{(t-1)}) + g_i f_t(x_i) + \tfrac{1}{2} h_i f_t^2(x_i) \right] + \Omega(f_t), \]

其中 \( g_i \) 和 \( h_i \) 是损失对当前预测的梯度与海森。二阶项使每一步成为兼顾曲率的牛顿式更新，这也是为什么海森之和之类的量贯穿整个实现。<sup>[1](https://arxiv.org/abs/1603.02754)</sup>

**正则化作用于树结构与叶权重。** 惩罚项 \( \Omega(f) = \gamma \cdot T + \tfrac{1}{2} \lambda \|w\|^2 \) 对每个叶节点收取 \( \gamma \)，并对叶权重向量 \( w \) 施加L2收缩。在参数接口中，gamma（min_split_loss，默认0）设定在叶节点上进一步划分所需的最小损失下降，lambda（reg_lambda，默认1）是权重的L2项，取值越大模型越保守。<sup>[1](https://arxiv.org/abs/1603.02754)</sup><sup> • </sup><sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup> 另有两项来自早期工作的过拟合控制：收缩（shrinkage），在每次提升步骤后以因子eta缩放新加入的权重，起到学习率的作用；以及借自随机森林的列（特征）子采样。<sup>[1](https://arxiv.org/abs/1603.02754)</sup>

## 面向速度与规模的工程

XGBoost提供三种CPU树方法。exact方法是原版梯度提升树算法，在寻找分裂时遍历输入数据的所有条目；它在贪心方法中更精确，但计算更慢。approx方法在构建每棵树之前运行草图，以海森作为草图权重使用全部行。hist方法源自LightGBM、实现上略有差异，在训练前用用户提供的权重运行一次草图，并在此全局草图上构建逐节点直方图；它是最快的算法，因为只做一次草图。<sup>[2](https://xgboost.readthedocs.io/en/release_3.0.0/treemethod.html)</sup> 对于海森为常数的目标（如reg:squarederror），文档推荐hist，因为常数权重下加权草图没有意义；海森非常数时，approx有时以更慢的计算换来更好的精度，而hist配合更高的max_bin往往能达到相近或更优的精度。<sup>[2](https://xgboost.readthedocs.io/en/release_3.0.0/treemethod.html)</sup>

**缺失值在结构层面得到处理。** 当某个值缺失时，算法在分裂处同时测试左右两个默认方向并选取增益更优者，因此含NaN的数据无需插补即可直接输入。<sup>[3](https://xgboost.org/papers/chen-guestrin-2016-annotated/)</sup>

文档中的能力表显示，exact方法不支持类别数据、外部内存或分布式训练，而approx和hist三者皆支持，GPU hist还额外支持基于梯度的采样。<sup>[2](https://xgboost.readthedocs.io/en/release_3.0.0/treemethod.html)</sup> 据原论文，在单机上XGBoost比广泛使用的替代方案快十倍以上，分布式或内存受限时可处理数十亿样本；核外计算还使其能在台式机上处理数亿样本。<sup>[1](https://arxiv.org/abs/1603.02754)</sup> 针对内存紧张的情形设有内存调节项：max_cached_hist_node于2.0.0版本加入，默认65536，控制hist和approx方法的直方图缓存大小，仅在遇到内存不足错误时才应设置。<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup>

## 数据说话

基准测试给出的图景复杂但可量化。在原论文的学习排序基准中，XGBoost每棵树耗时0.826秒，NDCG@10为0.7892；pGBRT每棵树2.576秒，NDCG@10为0.7915；列子采样取0.5将XGBoost的耗时降至0.506秒，同时将NDCG@10略升至0.7913。<sup>[1](https://arxiv.org/abs/1603.02754)</sup>

与主要竞争对手相比，耗时高度依赖数据集。LightGBM公布的实验报告称，在Higgs数据集上（eta 0.1、max_depth 8、500轮、16线程），LightGBM为130.094秒，exact XGBoost为3794.34秒，xgboost_hist为165.575秒；在Expo上分别为62.607秒对1607.35秒；在Allstate上分别为148.231秒对2867.22秒。内存也呈同样方向：Higgs上0.897 GB对4.853 GB，Allstate上1.116 GB对6.237 GB。<sup>[6](https://lightgbm.readthedocs.io/en/latest/Experiments.html)</sup> 微软的一项基准同样发现LightGBM在所有测试数据集上于CPU和GPU均更快，差距最高达XGBoost的25倍、XGBoost hist的15倍，而两个库的精度指标相近。<sup>[7](https://learn.microsoft.com/en-us/archive/blogs/machinelearning/lessons-learned-benchmarking-fast-machine-learning-algorithms)</sup> 独立的GBM-perf基准在小规模上给出相反结果：10万行时XGBoost最快，0.4秒对LightGBM的2.3秒；而1000万行时LightGBM训练最快，20秒且AUC最佳（0.792），领先于XGBoost的40秒（AUC 0.757）、h2o的60秒（0.776）和CatBoost的70秒（0.735）。<sup>[8](https://github.com/szilard/GBM-perf)</sup>

在GPU上，一项侧重硬件的基准发现XGBoost在三个库中GPU对CPU的加速比最高，平均7.26倍、中位数3.32倍，而CatBoost为3.7倍/2.17倍，LightGBM为2.35倍/0.75倍（排除goss例程后为3.57倍/1.32倍）。<sup>[9](https://arxiv.org/pdf/1809.04559)</sup> 同一研究指出，gpu_hist完全在GPU上建树以避免CPU-GPU传输，但在Epsilon（2008）等大型数据集上GPU内核因显存限制而失败，并得出结论：在所有数据集和任务上不存在明确的求解时间赢家。<sup>[9](https://arxiv.org/pdf/1809.04559)</sup> 微软的基准在可扩展性上得出相反结论，报告XGBoost的GPU实现在半数测试中内存耗尽，包括三个较大数据集上的内存不足错误，以及一次Airline数据集运行在5小时后被终止。<sup>[7](https://learn.microsoft.com/en-us/archive/blogs/machinelearning/lessons-learned-benchmarking-fast-machine-learning-algorithms)</sup> 在GBM-perf的内存受限GPU测试中，XGBoost用6 GB显存、无额外内存，80秒完成训练；而CatBoost在超过16 GB显存加14 GB额外内存时因内存不足而崩溃。<sup>[8](https://github.com/szilard/GBM-perf)</sup> CatBoost自己的基准测量8000棵树集成的平均建树时间，报告CatBoost为17.9毫秒、LightGBM为40毫秒、XGBoost为488毫秒。<sup>[10](https://github.com/catboost/benchmarks/blob/master/gpu_vs_cpu_training_speed/README.md)</sup>

## 与LightGBM、CatBoost及其他方法的比较

三大领先库最显著的差异在于树的生长策略与类别特征处理。XGBoost默认采用偏向靠近根节点分裂的按深度生长策略；LightGBM选择可用分裂增益最大的叶节点（按叶生长）；CatBoost默认的SymmetricTree对给定层级的每个节点施加相同的分裂条件。<sup>[11](https://insightful-data-lab.com/2025/03/14/xgboost-lightgbm-catboost-in-practice/)</sup> 对于类别特征，LightGBM用节点级梯度与曲率统计对类别排序并依此顺序搜索划分，而CatBoost从排列中较早的行构建平滑目标统计，排除当前行自身的目标。<sup>[11](https://insightful-data-lab.com/2025/03/14/xgboost-lightgbm-catboost-in-practice/)</sup>

精度比较因数据集而异。一项针对混合类型表格数据的六数据集基准发现，相对于MLP、表格Transformer和TabPFN，XGBoost与LightGBM始终在性能、校准和可解释性之间取得最佳平衡，在异构和不平衡数据上基于SHAP的归因比深度学习模型更稳定、更可解释。<sup>[12](https://www.worldscientific.com/doi/10.1142/S0218213026400038)</sup> 一项覆盖随机森林、XGBoost、LightGBM、CatBoost、MLP、TabNet、TabPFN和APT的更广泛六数据集研究发现，提升树通常仍接近干净数据上的最佳性能，同时在缺失值、高基数类别和协变量偏移下保持更强的鲁棒性和特征归因稳定性。<sup>[13](https://doi.org/10.57684/cos-1497)</sup> 所引的十数据集比较日期为2026年11月1日，晚于本文当前日期。<sup>[14](https://www.sciencepg.com/article/10.11648/j.mlr.20261101.14)</sup>

## 实际使用与调参

对模型复杂度影响最直接的参数在文档中记载如下。max_depth默认为6，增大它会使模型更复杂、更易过拟合；文档还警告XGBoost在训练深树时会大量消耗内存。eta（learning_rate）默认0.3，范围[0,1]，在每次提升步骤后收缩特征权重。min_child_weight默认1，指定子节点所需的实例权重（海森）之和的最小值，取值越大越保守。subsample默认1，设为0.5会在建树前随机抽取一半训练数据以防止过拟合。<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup> 对于极度不平衡的逻辑回归，max_delta_step默认0，取1到10可能有助于控制更新；欺诈检测文献同样强调scale_pos_weight是应对少数类梯度的参数。<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup><sup> • </sup><sup>[15](https://irojournals.com/iroismac/article/download/1052/938/1854)</sup>

**自定义目标是一等公民。** 该包在加权分类与排序目标之外支持用户自定义目标函数，通过二阶训练步骤所消费的梯度/海森接口暴露。<sup>[1](https://arxiv.org/abs/1603.02754)</sup>

**特征重要性分两个层次。** 内置分数为gain、weight和cover，可从训练好的树中低成本提取。至于归因，XGBoost通过TreeExplainer与shap包集成，高效计算精确SHAP值；SHAP由斯科特·伦德伯格（Scott Lundberg）和苏因·李（Su-In Lee）于2017年提出，使用合作博弈论中的沙普利值对预测进行归因。树集成的精确SHAP计算代价为 \( O(TLD^2) \)，其中 \( T \) 为树数、\( L \) 为最大叶数、\( D \) 为最大深度，远高于内置分数；由于SHAP具有理论一致性保证并能处理特征交互，它被推荐用于高风险或监管场景。<sup>[5](https://xgboost.org/concept/xgboost-feature-importance-methods/)</sup> 由于Tree SHAP在XGBoost内部实现，可在数千样本上快速计算精确值，且单次预测的SHAP值（含期望输出）之和等于该预测的模型输出。<sup>[16](https://shap.readthedocs.io/en/latest/example_notebooks/tabular_examples/tree_based_models/League%20of%20Legends%20Win%20Prediction%20with%20XGBoost.html)</sup>

## 近期进展

近期版本在功能与基础设施两方面都实现了现代化。3.3.0版本新增expectile回归，默认启用类别特征支持，使用户在常见情形下不再需要设置enable_categorical=True，并扩展了CPU和GPU上向量叶多输出树的SHAP支持。分位数草图经历大幅重构，改进了加权分位数草图并显著降低GPU内存占用。分布式训练不再需要全对全的集合通信连接，改用树归约进行分布式分位数构建，工作端口可自定义。CPU hist方法为向量叶模型增加了独热类别分裂支持，TreeSHAP针对数值稳定性更新并加快了QuadratureTreeSHAP执行，CPU直方图构建通过列块分块针对宽数据集优化。<sup>[17](https://xgboost.ai/2026/07/21/xgboost-3-3-release)</sup> 参数面随版本演进：max_cached_hist_node在2.0.0到来，max_cat_to_onehot在1.6.0加入，并在3.5.0中改为类别特征默认使用独热编码，低于阈值的特征使用独热分裂，其余使用基于划分的分裂。<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup>

向量叶模型是值得注意的架构变化：v2.0在CPU hist方法中做了原型，v3.4.1是其面向hist的首个功能完整实现，在每个叶节点存储权重向量，使多输出梯度训练能直接建模目标间的关系。<sup>[18](https://xgboost.ai/2026/08/25/introducing-the-xgboost-vector-leaf-model)</sup>

**来自基础模型的竞争并未取代它。** 在上述基准研究中，TabPFN等预训练表格模型缩小了与提升树的部分差距，但并未稳定超越它们。<sup>[13](https://doi.org/10.57684/cos-1497)</sup> XGBoost在竞赛中仍是顶级的单模型选择：Kaggle Playground Series S4E12（2024）的第一名方案就是一个使用611个工程特征的单一XGBoost模型。<sup>[19](https://www.kaggle.com/competitions/playground-series-s4e12/writeups/chris-deotte-1st-place-single-model-feature-engine)</sup>

## 采用、影响与批评

XGBoost的采用情况在竞赛和业界均有记载。在2015年之前的一年里，它是十余项机器学习挑战获胜方案中的主要系统，包括KDDCup，并被谷歌（Google）、阿里巴巴（Alibaba）和腾讯（Tencent）等行业用户以及多家初创公司采用。<sup>[20](http://learningsys.org/papers/LearningSys_2015_paper_32.pdf)</sup> 2015年Kaggle获胜方案涵盖商店销量预测、高能物理事件分类、网页文本分类、广告点击率预测、恶意软件分类和MOOC退课预测。<sup>[1](https://arxiv.org/abs/1603.02754)</sup> 在受监管的金融场景中，XGBoost在信用卡交易等结构化表格数据上显著优于经典方法，所引研究提出基于SHAP的逐笔交易解释，以在受GDPR和PCI-DSS约束的环境中支持透明性与可审计性。<sup>[15](https://irojournals.com/iroismac/article/download/1052/938/1854)</sup>

有记载的局限是具体的。过拟合风险随树深度和复杂度上升，这也是max_depth、min_child_weight、gamma、lambda、eta和subsample在文档中都带有保守方向指引的原因。<sup>[4](https://xgboost.readthedocs.io/en/stable/parameter.html)</sup> 在系统层面，大型数据集上的GPU显存限制是多项独立基准反复出现的发现，即便问题的严重程度尚有争议。<sup>[9](https://arxiv.org/pdf/1809.04559)</sup><sup> • </sup><sup>[7](https://learn.microsoft.com/en-us/archive/blogs/machinelearning/lessons-learned-benchmarking-fast-machine-learning-algorithms)</sup> 可解释性局限在实践中通过SHAP解决，其精确树算法与可加性使逐预测解释可大规模实现，项目自身的指引也推荐将其用于高风险和监管用途。<sup>[5](https://xgboost.org/concept/xgboost-feature-importance-methods/)</sup><sup> • </sup><sup>[16](https://shap.readthedocs.io/en/latest/example_notebooks/tabular_examples/tree_based_models/League%20of%20Legends%20Win%20Prediction%20with%20XGBoost.html)</sup>

## References

1. [Tianqi Chen, Carlos Guestrin (2016). XGBoost: A Scalable Tree Boosting System. KDD 2016 / arXiv.](https://arxiv.org/abs/1603.02754)
2. [XGBoost Tree Methods, official documentation (release 3.0.0)](https://xgboost.readthedocs.io/en/release_3.0.0/treemethod.html)
3. [Chen & Guestrin 2016, Annotated Reading, xgboost.org](https://xgboost.org/papers/chen-guestrin-2016-annotated/)
4. [XGBoost Parameters, official documentation](https://xgboost.readthedocs.io/en/stable/parameter.html)
5. [Feature Importance in XGBoost: Gain, Weight, Cover, and SHAP, xgboost.org](https://xgboost.org/concept/xgboost-feature-importance-methods/)
6. [LightGBM documentation, Experiments](https://lightgbm.readthedocs.io/en/latest/Experiments.html)
7. [Lessons Learned From Benchmarking Fast Machine Learning Algorithms, Microsoft ML blog](https://learn.microsoft.com/en-us/archive/blogs/machinelearning/lessons-learned-benchmarking-fast-machine-learning-algorithms)
8. [GBM-perf: benchmark of GBM tools](https://github.com/szilard/GBM-perf)
9. [Benchmarking and Dissecting the Nvidia GPU Hardware: A Case Study on the GBDT Libraries XGBoost, LightGBM and CatBoost](https://arxiv.org/pdf/1809.04559)
10. [CatBoost official benchmarks, GPU vs CPU training speed](https://github.com/catboost/benchmarks/blob/master/gpu_vs_cpu_training_speed/README.md)
11. [XGBoost vs LightGBM vs CatBoost, Measured](https://insightful-data-lab.com/2025/03/14/xgboost-lightgbm-catboost-in-practice/)
12. [Beyond Accuracy: A Comprehensive Comparative Study of Gradient Boosting Versus Tabular Deep Learning, World Scientific](https://www.worldscientific.com/doi/10.1142/S0218213026400038)
13. [Understanding Tree Model Dominance in Tabular Learning](https://doi.org/10.57684/cos-1497)
14. [Gradient Boosting Revisited: Comparative Analysis of Selected Advances on Real-World Tabular Data](https://www.sciencepg.com/article/10.11648/j.mlr.20261101.14)
15. [Smart and Explainable Credit Card Fraud Detection, IRO Journals](https://irojournals.com/iroismac/article/download/1052/938/1854)
16. [League of Legends Win Prediction with XGBoost, SHAP documentation](https://shap.readthedocs.io/en/latest/example_notebooks/tabular_examples/tree_based_models/League%20of%20Legends%20Win%20Prediction%20with%20XGBoost.html)
17. [XGBoost 3.3.0 Release, xgboost.ai](https://xgboost.ai/2026/07/21/xgboost-3-3-release)
18. [Introducing the XGBoost Vector-Leaf Model, xgboost.ai](https://xgboost.ai/2026/08/25/introducing-the-xgboost-vector-leaf-model)
19. [1st Place, Single Model, Feature Engineering, Kaggle Playground S4E12](https://www.kaggle.com/competitions/playground-series-s4e12/writeups/chris-deotte-1st-place-single-model-feature-engine)
20. [XGBoost: Reliable Large-scale Tree Boosting System, LearningSys 2015 workshop](http://learningsys.org/papers/LearningSys_2015_paper_32.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Ensemble, boosting, and transfer methods › Boosting algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/xgboost

English original: https://www.edgepedia.org/xgboost
