TL;DR
XGBoost is a system for gradient tree boosting that is fast enough to train on billions of examples. The paper adds four ideas to the basic method: a split rule that handles missing and sparse values, a weighted quantile sketch for choosing split candidates on large or distributed data, a cache-friendly data layout, and out-of-core training from disk. On the paper's benchmarks it reached accuracy close to the baselines it was compared with, and it ran much faster.
Builds on: Gradient Boosting, Decision Tree, Hessian Matrix, L2 Regularization, Weighted Quantile Sketch · Leads to: gradient boosting as used in practice
Why it mattered
The paper's own count is the clearest measure. Among the 29 winning Kaggle solutions published in 2015 that the authors examined, 17 used XGBoost, and eight used it alone. The second most common method, deep neural nets, appeared in 11. Every winning team in the top ten of KDDCup 2015 used it.
The paper's comparison table (Table 1) sets XGBoost against other tree boosting systems on six features: exact greedy search, global and local approximate search, out-of-core training, sparsity awareness and parallelism. XGBoost is the only system marked yes on all of them. It trains on one machine with data on disk, and it spreads work over a cluster when needed. Its open-source package is used from Python, R and Julia, and it fits into scikit-learn pipelines.
The problem
Gradient boosting builds a model as a sum of trees. Each new tree must be chosen to lower a loss that depends on the current prediction. The hard part is the split search: at each node, the learner must pick a feature and a threshold. The exact method tries every distinct value of every feature, after sorting the data. That is accurate, but sorting and scanning cost time, and the data must fit in memory.
Three practical problems follow. The data is often sparse, with many zeros, one-hot columns or missing entries, and the learner needs a principled way to handle missing entries. The data may not fit in memory, or may be split across machines, so the exact method cannot run. And the work of reading gradient statistics in feature order jumps around memory, which makes the CPU wait for the cache. XGBoost addresses all three.
How it works
Think of XGBoost as a pipeline that runs once for each tree.
- Load the data into blocks. Each feature column is stored sorted by value, in compressed column format, in blocks. The sorting is paid once, before training, and reused in later trees.
- Compute the gradient statistics. For each row i, compute , the first derivative of the loss at the current prediction, and , the second derivative. These are the only numbers the tree learner needs from the loss.
- Choose the split candidates. For the exact method, every distinct value is a candidate. For the approximate method, each feature is cut at candidate points chosen by the weighted quantile sketch, which uses as the weight of each row.
- Score each split and pick the best. A split is scored from the sums of and on each side. Rows with a missing value go to a default direction, learned from the data, that is chosen to make the score highest.
- Set the leaf values. Each leaf gets a value computed from the sums of and in that leaf.
- Add the tree with shrinkage. The new tree is multiplied by a factor before it is added, which the paper calls shrinkage. Then go back to step 2 for the next tree.
Step 3 is where the approximate method saves work. The exact method scans every value; the approximate one scans only the buckets, with sums of and aggregated per bucket.
flowchart LR A["Sorted blocks of features"] --> B["Gradient statistics g and h"] B --> C["Candidate splits: exact or sketch"] C --> D["Score splits with sums of g and h"] D --> E["Leaf values and new tree"] E --> F["Add tree times shrinkage"] F --> B
Here is one split traced by hand. Four rows have targets y = (1, 1, 3, 3), the current prediction is 0 everywhere, and the loss is squared error, so and . Use and . Try the split that puts rows 1 and 2 on the left.
- Left sums: and . Check: two rows, each with h = 1.
- Right sums: and . Check: the totals are and .
- Score each side as : left , right , and the whole .
- The gain is . Check: a positive gain means the split helps.
- Leaf values are : left and right . Check: each leaf value is pulled toward its rows' targets, and the shrinkage then scales it.
The math
The model is a sum of regression trees, , where maps an input to the score of its leaf under the tree structure . The learning objective adds a penalty on tree size and leaf values:
Here is the number of leaves, is the cost of each leaf, and shrinks leaf values, which is the L2 penalty named in the requirements. The paper notes that when the regularization is set to zero, the objective falls back to traditional gradient tree boosting.
Step 2 in symbols
Add tree to the prediction from the previous round. A second-order Taylor expansion of the loss gives
with and . Removing the constant gives . For a second derivative of a loss in one prediction, is just a number per row.
Step 4 in symbols
Let be the set of rows in leaf j. Collecting terms per leaf gives
Setting the derivative in each to zero gives the best leaf value and the best score for a fixed structure:
The score is the sum over leaves of , where and are the sums of and in that leaf. This is the form used in the walkthrough above.
The split gain in symbols
For a split of node into and , the loss reduction is
Each split is accepted when this is positive and largest among the candidates. The approximate method uses the same formula, with the sums taken over buckets.
Step 3 in symbols, the sketch
The approximate method needs candidate cut points for feature k. The rank of a value is the share of below it:
The sketch picks candidates such that consecutive ranks differ by less than , with the smallest and largest values included. The paper says there are then roughly candidates. The Weighted Quantile Sketch lesson works through this.
Results
The paper reports results on four datasets (Allstate, Higgs Boson, Yahoo! LTRC and Criteo). Experiments used maximum depth 8 and shrinkage 0.1 unless noted.
- Exact method against two other tools (Higgs-1M, 500 trees, Table 3). XGBoost took 0.6841 seconds per tree with test AUC 0.8304. scikit-learn took 28.51 seconds per tree with AUC 0.8302. R's gbm took 1.032 seconds with AUC 0.6224. The paper says XGBoost runs more than 10 times faster than scikit-learn. The paper attributes gbm's lower accuracy to its greedy method, which expands only one branch of a tree: faster, but it can lose accuracy.
- Learning to rank (Yahoo! LTRC, 500 trees, Table 4). XGBoost took 0.826 seconds per tree with NDCG@10 of 0.7892. With column subsampling at 0.5 it took 0.506 seconds with 0.7913. pGBRT took 2.576 seconds with 0.7915.
- Sparsity-aware split finding. On Allstate-10K the sparsity-aware algorithm was more than 50 times faster than the naive version.
- Cache-aware exact greedy. On large data, the cache-aware version ran twice as fast as the naive one (Figure 7).
- Block size. The paper chose examples per block, which balances cache misses against parallel work (Figure 9).
- Compression for disk. Block compression reached roughly a 26 to 29 percent compression ratio on most datasets tested. On Criteo, compression gave a 3 times speedup and sharding over two disks another 2 times (Figure 11).
- Scale. The final out-of-core method processed all 1.7 billion Criteo examples on a single machine.
- Distributed comparison (32 EC2 nodes, 10 iterations, Figure 12). The paper reports XGBoost ran more than 10 times faster than Spark per iteration and 2.2 times faster than H2O's optimized version. Spark slowed sharply when it ran out of memory.
The limits are real. Most timing comparisons are on specific hardware, and the scikit-learn comparison uses the 1M subset because the baseline is slow. The column-subsampled model was slightly less accurate on Higgs but slightly more accurate on Yahoo!, so subsampling is a tuning choice, not a free win. The paper's accuracy claims are for the datasets it tested.
Reading guide
- Section 1 (Introduction). Read with Gradient Boosting and Ensemble Learning in mind. It lists the contributions and the Kaggle evidence.
- Section 2 (Tree boosting in a nutshell). Needs Decision Tree, Taylor Series, Hessian Matrix and L2 Regularization. Equation (2), the tree ensemble model, and Equation (7), the split score, are the core of the paper.
- Section 3.1 (Exact greedy). Sorting the data and scanning it, which the block structure later makes cheap.
- Sections 3.2 and 3.3 (Approximate algorithm and weighted quantile sketch). Need Weighted Quantile Sketch. Appendix A holds the proofs of the merge and prune guarantees.
- Section 3.4 (Sparsity-aware split finding). Needs Sparse Matrix and the idea of an indicator column, since one-hot encoding creates many sparse columns.
- Section 4 (System design). Blocks, cache-aware access and out-of-core computation. Read for the engineering, not for new statistics.
- Section 5 (Related work). Column sampling is borrowed from Random Forest, and the paper places XGBoost among earlier parallel tree boosting systems.
- Section 6 (End-to-end evaluations). Uses AUC for classification and NDCG for ranking. Tables 3 and 4 and Figures 10 to 13 are the results.
- Section 7 (Conclusion). A short summary of the lessons.
Check yourself
QuestionWhat are and in the XGBoost objective?Show answer
QuestionFour rows have g = (-1, -1, -3, -3) and h = 1 each, with and . Compute the leaf value for the right leaf, which has rows 3 and 4 only.Show answer
QuestionWhy does the approximate method use the sum of rather than the number of rows to place its candidates?Show answer
QuestionThe paper reports 17 of 29 winning Kaggle solutions used XGBoost. What fraction is that, and what does the paper add about the eight that used XGBoost alone?Show answer
Sources
- Chen and Guestrin, "XGBoost: A Scalable Tree Boosting System," arXiv 1603.02754 (2016).
- The same paper, KDD 2016, ACM DOI 10.1145/2939672.2939785.
- Wikipedia, "XGBoost."