Lessons › Chapter 6: Trees and ensembles
Gradient boosting
Gradient boosting begins with the simplest possible guess for every house: the average price. The dashed lines show how far off that is.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Squeezing out accuracy
To predict how much customers will spend next month, Leo tries the method that wins most competitions on table data.
Start with a simple guess
Gradient boosting begins with the simplest possible guess for every house: the average price. The dashed lines show how far off that is.
Fit a tree to the leftovers
Measure the errors that remain (bars in front). Then train a small tree whose only job is to predict those errors.
Add a small correction
Add a small slice of that tree’s output to the prediction. The line bends toward the data, and the leftover errors shrink.
Repeat, many times
Do it again and again, each tree fixing what is still wrong. After a few rounds the predictions hug the data. In practice you stop early, using a validation set, before it starts memorizing noise.
In real life: arrival times, prices and rankings
Gradient-boosted trees power many predictions made from tables of data: delivery and ride arrival times, dynamic prices, search ranking and credit risk. On table data they are often the model to beat.
Quick check: What does each new tree in gradient boosting try to predict?
- The original labels again
- The errors that are left over (correct)
- Random noise
Each tree models the remaining errors, so adding it corrects the ensemble.
Pseudocode
prediction = the average price # start simple
repeat 100 times:
errors = true − prediction # what we still get wrong
tree = small tree that predicts the errors
prediction = prediction + 0.1 × tree # a small correction
# XGBoost, LightGBM and CatBoost are fast versions of this