Sub topic 1
Decision Trees as Weak Learners
Prerequisites.
Assume you know Python and NumPy, supervised learning, train/validation splits, and the basic structure of a decision tree. You should also recognize overfitting and understand a loss function as a measure of prediction error.
Decision trees as weak learners
A decision tree predicts by splitting data with rules such as age < 30. A leaf stores a prediction for the examples that reach it. A shallow tree has limited capacity, so it may underfit when used alone. Such a model is called a weak learner: its predictions are only somewhat useful, but they can improve a larger model.
Boosting: building an ensemble one tree at a time
Boosting combines many weak learners into one strong learner. Unlike bagging, which trains trees independently on different samples, boosting trains trees sequentially.
The first tree makes an initial prediction. The next tree focuses on the current model's errors. Each later tree adds a correction while preserving the previous trees' predictions.
A learning rate controls how much each tree changes the ensemble. Smaller values usually require more trees but can improve generalization.
Loss functions and their gradients
A loss function measures the difference between a prediction and its target. Squared error is common for regression. Log loss is common for binary classification.
The gradient is the derivative of the loss with respect to the model's current prediction. Its negative points toward lower loss. Gradient boosting fits each new tree to these negative gradients, often called pseudo-residuals.
For squared error, the negative gradient is proportional to:
target - current prediction
Therefore, the next tree learns to predict the remaining error.
The gradient boosting algorithm
- Start with a simple prediction, such as the mean target.
- Compute each training example's negative gradient.
- Fit a shallow tree to those values.
- Multiply the tree's output by the learning rate.
- Add the result to the current prediction.
- Repeat for a chosen number of rounds.
The final prediction is the sum of the initial prediction and all tree corrections.
What XGBoost adds: regularized objective with gradients and hessians
XGBoost extends gradient boosting with a regularized objective. Regularization penalizes complex trees, reducing overfitting. The objective includes both training loss and a penalty for tree structure, such as the number and size of leaves.
For each example, XGBoost uses:
- A gradient, the first derivative of the loss.
- A hessian, the second derivative, which describes how the gradient changes.
Using both gives a second-order approximation of the loss. XGBoost uses this approximation to evaluate candidate splits efficiently and choose useful ones. It also supports shrinkage, row and column sampling, missing-value handling, and fast histogram-based training.
Exercise
Why does gradient boosting add trees sequentially instead of training them independently?
Show answer
Each new tree learns to reduce the current ensemble's loss by modeling its negative gradients.