Gradient boosting is a machine learning technique that builds a strong predictive model by adding many small models, usually decision trees, one at a time, with each new tree correcting the errors of the ones before it. The scikit-learn user guide describes gradient tree boosting as a generalisation of boosting to arbitrary differentiable loss functions, and calls it an excellent model for regression and classification, in particular for tabular data.
This page is for data scientists, ML engineers and technical leaders who want to understand how gradient boosting works, how it compares with other models, how to keep it from overfitting, and where it fits in AI agent systems.
What is gradient boosting?
Boosting combines weak learners into a strong one. In gradient boosting, each new tree is fitted to the negative gradient of the loss for the current predictions. The scikit-learn user guide calls this a kind of gradient descent in a functional space.
The XGBoost documentation gives the same idea in plain terms: fix what has been learned, and add one new tree at a time. The final prediction is the sum of the scores from all the trees.
How does gradient boosting work?
- Start with a simple initial prediction.
- Measure the error with a loss function.
- Fit a small tree to the gradient of that loss, which for squared error is the residual, the part the ensemble still gets wrong.
- Add the new tree to the ensemble, scaled by a learning rate.
- Repeat until the validation error stops improving.
The XGBoost documentation adds that the training objective has two parts: a loss that measures fit, and a regularisation term that controls model complexity and helps avoid overfitting.
How do you stop gradient boosting from overfitting?
The scikit-learn user guide names several controls. The learning rate, a value above 0 and up to 1, controls overfitting through shrinkage. Smaller values need more trees, and the guide cites a small constant such as 0.1 or less, with enough trees that early stopping applies.
Subsampling trains each tree on a fraction of the data, drawn without replacement, which is called stochastic gradient boosting. The guide gives 0.5 as a typical value. Limiting the number of features per split can also cut runtime. Early stopping uses a validation set to pick the number of trees.
How is gradient boosting different from other models?
| Approach | How it builds the model | Best known for |
| Gradient boosting | Trees added in sequence, each correcting the current ensemble | Strong results on tabular data |
| Random forest | Many trees trained independently, then combined | Combining independent trees by averaging or voting |
| Single decision tree | One tree | A simple, readable building block |
| Neural network | Layers of weights trained together | Deep learning on unstructured data |
The scikit-learn user guide also notes limits. Multiclass problems are costly, because one tree per class is built at each step. For large datasets it recommends the histogram-based estimators, which it says can be orders of magnitude faster beyond tens of thousands of samples.
What is gradient boosting used for?
It is a common choice for tabular problems such as credit and fraud scoring, churn prediction, demand forecasting and ranking, where the inputs are columns in a table. Libraries such as XGBoost, LightGBM and CatBoost implement it, and scikit-learn includes its own estimators.
How does gradient boosting relate to AI agents?
AI agents often call a trained model, such as a boosted-tree score for risk or churn, as one step in a larger workflow. The agent then acts on that score, so the model version, its inputs and the rule that applied should be traceable. ElixirClaw, XenonStack's AI agents computing platform, is where such agents are built and run.
What should you do first?
- Start with a baseline model so you can measure improvement.
- Split the data into training, validation and test sets.
- Use a small learning rate and enable early stopping.
- Tune tree depth and subsampling before adding more trees.
- Record the model version and inputs behind every decision an agent takes.
To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is gradient boosting in simple terms?
Gradient boosting builds a model in steps. Each new small tree is trained to fix the errors that the trees before it still make, and the trees are added together to give the final prediction.
What is the difference between gradient boosting and random forest?
A random forest trains many trees independently and combines them. Gradient boosting trains trees in sequence, with each tree correcting the current ensemble.
Which libraries implement gradient boosting?
Common implementations are XGBoost, LightGBM and CatBoost, along with the gradient boosting estimators in scikit-learn. Teams often benchmark two or three on their own data.
How do you prevent overfitting in gradient boosting?
Use a small learning rate, subsample rows and features, regularise the trees, and apply early stopping on a validation set.
When does gradient boosting work best?
It works best on structured, tabular data, where it is a strong default for regression and classification.