TL;DR
A tree learner that boosts needs a short list of candidate split points for each feature. Testing every distinct value is too slow on a large table, so the candidates are chosen from the feature's boosting statistics. The weighted quantile sketch chooses them so that each gap between neighbouring candidates holds an even share of the weights, where each row's weight is its second-order statistic. It works from a compact summary, so the summaries from many machines can be merged and still carry a stated error bound.
Builds on: Gradient Boosting, Decision Tree, Cumulative Distribution Function, Taylor Series · Leads to: XGBoost
Where it's used
- XGBoost on large tables. The XGBoost paper describes a system that is "used widely by data scientists to achieve state-of-the-art results on many machine learning challenges." The sketch is how that system picks split candidates for a feature without testing every distinct value.
- Training across many machines. Each machine builds a summary of its own rows. Two summaries can be merged into one, and the merged summary keeps the error of the worse input. The paper calls this a distributed weighted quantile sketch, and it is the reason the summary is built from merge and prune operations.
- Checking that approximation costs little accuracy. The paper's Figure 3 compares test AUC on the Higgs 10M dataset, which has 10 million training instances, for several settings of the sketch's approximation parameter. The paper reports that the quantile strategy "can get the same accuracy as exact greedy given reasonable approximation level."
How it works
Take one feature, x, and five rows. Each row also has a weight h, which in boosting is the second derivative of the loss at the current prediction. For now, read h as "how much this row should count."
| Row value x | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Weight h | 1 | 1 | 4 | 1 | 1 |
The goal is a short list of cut points, such as 5, that splits the weight into roughly equal pieces. A plain percentile would count rows. This one counts weight.
- Add up the weights. 1 + 1 + 4 + 1 + 1 = 8. Check: the total is 8, not 5, because the row at x = 3 counts four times.
- Turn the weights into a running share. Divide each running total by 8. After x = 1 the running total is 1, a share of 1/8 = 0.125. After x = 2 it is 2, a share of 0.25. After x = 3 it is 6, a share of 0.75. After x = 4 it is 7, a share of 0.875. After x = 5 it is 8, a share of 1. Check: the last share is 1, as it must be.
- Set targets every 0.25 of the share. The targets are 0.25, 0.5, 0.75 and 1. For each target, take the first value whose running share reaches it. The target 0.25 is reached at x = 2. The targets 0.5 and 0.75 are both reached at x = 3, because its running share is 0.75. The target 1 is reached at x = 5. Check: three targets, with one value covering two of them.
- Add the minimum. The cut points are the minimum, 1, plus the values from step 3: 5. Check: the largest value, 5, is always a cut point.
- Compare with plain quantiles. Without weights the running shares are 0.2, 0.4, 0.6, 0.8 and 1, so the same targets would be reached at x = 2, 3, 4 and 5. The cut at 4 disappears in the weighted version because the heavy row at 3 already covers the 0.75 target. Check: the weighted list has one fewer cut in the region where the weight is concentrated.
flowchart LR A["Sort the rows by feature value"] --> B["Running share of the total weight"] B --> C["Targets every epsilon: 0.25, 0.5, 0.75, 1"] C --> D["First value that reaches each target"] D --> E["Candidate cut points"]
The paper says there are roughly 1/epsilon candidates, where epsilon is the approximation factor. With epsilon = 0.25 that is about four, which matches the four targets above.
The math
Write the rows as pairs with , and let be the total weight. The rank function is the share of the weight on values strictly below z. Step 2 of the walkthrough uses a close cousin of it, the running share, defined below.
Step 1 in symbols
The total is .
Step 2 in symbols
The running share at a value z counts the weight at values less than or equal to z:
For the example, and . The weight sitting exactly at z is what separates R from r: . At z = 3 the weight at 3 is 4, so , which matches the rank above.
Step 3 in symbols
For a target t, the candidate is the smallest value s with . With the targets are for . Here already satisfies both and , so one value serves two targets.
Step 4 in symbols
The candidate set is , which gives .
Why the weights are the second derivatives
This is the step that connects the sketch to boosting. Suppose the current prediction for row i is , and a new tree adds a value to it. A second-order Taylor expansion of the loss gives
where is the first derivative of the loss and is the second derivative, both taken with respect to the prediction. Summed over rows, the split score depends on the data only through the and .
Complete the square in f:
The last term does not depend on f. So choosing the tree is the same as fitting a squared loss with label and weight . A split that is good for that weighted squared loss is good for boosting, and the candidate cuts should therefore spread the weight evenly, not the rows. This is the reason for the weights in the sketch.
Two standard losses show what h looks like:
- For squared error, gives and . Every row has weight 1, so the sketch is an ordinary quantile.
- For logistic loss, with predicted probability , and . A row at has . A row at has , so rows the model is sure about count for little.
The summary and its error
The sketch stores a summary that supports two operations, proved in the paper's appendix:
- Merge. Two summaries with errors and combine into one with error .
- Prune. A summary with error is cut down to values, and its error becomes .
Merging lets each machine work on its own rows. Pruning keeps the summary small.
Worked examples
Rows (x, h): (1, 1), (2, 2), (3, 1). Use .
- Total weight: .
- Running shares: after x = 1, . After x = 2, . After x = 3, .
- Targets: 0.5 and 1.0.
- Target 0.5 is first reached at x = 2, whose share is 0.75. Target 1.0 is reached at x = 3.
- Add the minimum, x = 1. The candidates are .
Interpretation: the row at x = 2 carries half the weight, so it is the cut that serves the middle target.
Rows x = 1 to 8, each with h = 1, as with squared error. Use .
- Total weight: 8.
- The running share after x is , so the shares are 0.125, 0.25, 0.375, ..., 1.
- Targets: 0.25, 0.5, 0.75 and 1.0.
- The targets are first reached at x = 2, 4, 6 and 8.
- Add the minimum, x = 1. The candidates are : four buckets of equal weight, which is .
Interpretation: with equal weights the sketch is an ordinary quantile sketch, and the paper says that is the case that existing algorithms already solved.
A training column has 1,000,000 rows with equal weights, and the approximation factor is .
- The number of targets is .
- Each bucket holds of the total weight, which is rows.
- The candidates fall about every 10,000 rows in sorted order.
- Now change the loss to logistic. Each row at has weight 0.25, about 25 times a row at (weight 0.0099). Each unsure row counts for about 25 confident rows, so the candidates crowd into the region of unsure rows.
Try it: a column has 250,000 rows with equal weights, and . How many targets are there, and how many rows fall in each bucket? Answer: targets, and rows per bucket.
Common mistakes and tradeoffs
It is tempting to think the sketch is just a percentile of the feature. In fact each row counts with its weight , which in boosting is the second derivative of the loss. A row the model is confident about counts for little, so the cut points move toward the rows the model is unsure about. Plain percentiles would ignore that.
It is tempting to think is a sample weight the user supplies. In fact the boosting loop computes it from the loss and the current predictions, and it changes every round.
It is tempting to think the candidates are exact. In fact they are approximate, and sets how far off they can be. More candidates cost time and memory, so is a tradeoff between accuracy and speed.
Use the sketch when the data is large and the splits must be found approximately, for example when training is distributed. Do not use it on a small table: the paper also supports exact greedy search on a single machine, which needs no candidate list. A different alternative is approximate histograms of gradient statistics, which the paper cites as a route used by earlier distributed systems. Both are alternatives to the sketch, not corrections to it.
History
Quantile summaries were studied in the database community. Greenwald and Khanna's 2001 paper, "Space-efficient online computation of quantile summaries," gave a summary that answers quantile queries with a stated accuracy, and later work extended it. Those methods assumed every row counts the same. Boosting needs rows to count by . The XGBoost paper, published in 2016, says that to its authors' knowledge the weighted sketch it introduced was the first method for that problem. Its merge and prune operations let the sketch run on many machines, which is part of why XGBoost spread quickly.
Recap
- Gradient boosting fits each new tree to the first and second derivatives of the loss, called and .
- A tree needs candidate cut points for each feature before it can score a split.
- Ordinary quantiles spread the candidates evenly by row count.
- The Taylor expansion of the loss shows that the split score is a weighted squared loss with weights , so the candidates should spread the weight .
- The sketch keeps a summary that merges across machines and prunes to a fixed size, with a stated error.
Read next: the XGBoost paper (Chen and Guestrin, 2016) for the full system, and Histogram for the binning alternative.
Check yourself
QuestionWhat is in the weighted quantile sketch?Show answer
QuestionRows x = 1, 2, 3, 4 have weights h = 2, 1, 1, 4. Find the candidate cut points for .Show answer
QuestionWhy does the sketch weight rows by instead of counting them?Show answer
QuestionA model gives for most rows of a feature and for a few others, under logistic loss. Where do the candidate cut points land, and why?Show answer
Sources
- Chen and Guestrin, "XGBoost: A Scalable Tree Boosting System," arXiv 1603.02754, Section 3.3 and Appendix A.
- The same paper, ACM DOI 10.1145/2939672.2939785.
- Wikipedia, "Quantile."