Math & Machine Learning Foundations
Trees and Ensembles: Decision Trees, Random Forests and Gradient Boosting
Intermediate 40 min For: Developers / Researchers
Key takeaways
- ▸A decision tree recursively splits samples into purer subsets with feature thresholds. CART grows a binary tree, typically using Gini impurity for classification and squared error for regression. The quality of a split is the size-weighted impurity of the two children, and the algorithm chooses the feature and threshold that minimise that quantity.
- ▸A single tree can fit the training set to zero error, so depth, leaf size or cost-complexity pruning must be controlled. Splits depend only on the order of feature values, so standardising features usually leaves the predictions unchanged; with the same random seed this lesson obtained identical test predictions.
- ▸Bagging averages models trained on bootstrap samples in order to reduce variance. Random forests also search only a random subset of features at each node, which de-correlates the trees. Boosting adds models sequentially: AdaBoost up-weights examples the previous round got wrong, and gradient boosting fits the negative gradient of the current loss (the residual, when the loss is squared error).
- ▸XGBoost uses a second-order Taylor expansion of a regularised objective to set leaf values and split gain, and does not split when the gain is smaller than gamma. The paper also gives a sparsity-aware split algorithm and a weighted quantile sketch for approximate splits. LightGBM uses histograms, leaf-wise growth, and the paper’s GOSS and EFB techniques to cut computation; num_leaves and min_data_in_leaf are the main controls against overfitting.
- ▸On a single train/test split of California Housing, an unpruned tree had a test RMSE of 0.7312, a random forest 0.4875, and, with the settings in this lesson, LightGBM 0.4387 and XGBoost 0.4430. Both SHAP and permutation importance flag location and income as the main factors, but they do not rank the features identically, because they answer different questions.
Summary. A decision tree carves the input space into purer subsets with a sequence of feature thresholds. The rules are readable, but a single tree overfits easily. Combining many trees is one of the most widely used approaches on tabular data: a random forest reduces variance with bagging and feature sampling; gradient boosting fits residuals, or more generally the loss gradient, in sequence. This lesson proceeds from splits and pruning, through bagging and random forests, AdaBoost and gradient boosting, to XGBoost and LightGBM, and ends with a comparison and an explanation on the same data. Every figure in the text comes from the runnable example at the end, using scikit-learn 1.9.1, XGBoost 3.4.1, LightGBM 4.7.0 and SHAP 0.54.1, with OMP_NUM_THREADS=3 and random seed 0.
This lesson belongs to the unit Trees and Ensembles. It builds on Overfitting, Generalisation and Data Splits and The Machine Learning Workflow. The entropy subsection is consistent with Probability, Statistics and Information Theory. Related algorithm cards: Decision Trees (CART), Random Forests, AdaBoost, Gradient Boosting, XGBoost and LightGBM.
What problem do tree models solve?
A tree partitions the input space into rectangular regions and predicts a constant in each region (the majority class or class probabilities for classification; the mean of the target for regression). Each split involves one feature and one threshold, which has several consequences:
- The rule can be read as a sequence of if–then tests and is easy to visualise.
- A split depends only on the order of the feature values, so standardisation is usually unnecessary. Some implementations can split on categorical features directly, without one-hot encoding. The scikit-learn 1.9 decision-tree documentation states that its CART implementation does not currently support categorical features; LightGBM and XGBoost can handle them directly when the corresponding options are enabled.
- Trees are relatively insensitive to outliers and to the scale of the features, which is why they are a strong baseline on tabular problems such as house prices, credit scoring and click-through rates.
Images and text, which have strong spatial or sequential structure, are usually a better fit for convolutional networks or Transformers than for an ordinary decision tree on raw pixels or tokens.
A single split: Gini impurity and information gain
Let p_mk be the proportion of class k in node m. The scikit-learn decision-tree documentation gives two common classification impurities:
- Gini impurity:
H = ∑_k p_k (1 − p_k). For two classes this is2 p (1 − p). It is largest atp = 0.5and is 0 on a pure node. - Entropy (log loss):
H = − ∑_k p_k log p_k. The numerical example below uses base 2; a pure node is again 0, and a balanced two-class node has entropy 1.
A candidate split that produces a left child and a right child is scored by the size-weighted impurity:
G(Q, t) = (n_L / n) H(Q_L) + (n_R / n) H(Q_R)
The algorithm chooses the feature and threshold that minimise G. For entropy, the impurity of the parent minus G is the information gain; for Gini, the corresponding difference is the Gini gain. Regression replaces H with the within-region squared error (or another regression criterion), with the same structure.
A 12-sample example with one numeric feature can be computed by hand. The root has six examples of each class, so the Gini impurity is 0.5000 and the entropy is 1.0000. Four candidate thresholds give the following results.
| Threshold t | Left n / class counts | Right n / class counts | Weighted Gini | Gini gain | Weighted entropy | Information gain |
|---|---|---|---|---|---|---|
| 1.5 | 2 / [2, 0] | 10 / [4, 6] | 0.4000 | 0.1000 | 0.8091 | 0.1909 |
| 2.5 | 4 / [4, 0] | 8 / [2, 6] | 0.2500 | 0.2500 | 0.5409 | 0.4591 |
| 5.5 | 6 / [5, 1] | 6 / [1, 5] | 0.2778 | 0.2222 | 0.6500 | 0.3500 |
| 8.5 | 8 / [5, 3] | 4 / [1, 3] | 0.4375 | 0.0625 | 0.9067 | 0.0933 |
Among these candidates the best split is t = 2.5, not the mid-gap value t = 5.5. For Gini, the left child at t = 2.5 is pure (H = 0) and the right child has counts [2, 6], so H = 2 × (2/8) × (6/8) = 0.375 and the weighted sum is (8/12) × 0.375 = 0.2500, a gain of 0.2500. At t = 5.5 both sides are impure, the weighted Gini is 0.2778 and the gain is only 0.2222. The criterion is the drop in impurity, not the geometric midpoint on the feature axis.
Growth is greedy: each node chooses the best split for itself and does not backtrack. Stopping rules include reaching max_depth, having fewer than min_samples_split samples, or obtaining an impurity decrease smaller than min_impurity_decrease (see the scikit-learn documentation).
CART, ID3 and the scikit-learn implementation
Quinlan’s ID3 (1986) uses information gain to make multi-way splits on categorical features, grows the tree to its full size and then prunes. C4.5 is its successor and removes the restriction that features must be categorical. CART (Classification and Regression Trees) by Breiman, Friedman, Olshen and Stone (1984) is close to C4.5, but it supports a numeric target (regression), grows a binary tree rather than a rule set, and uses cost-complexity pruning. The scikit-learn documentation states that it implements an optimised form of CART, choosing at each node the feature and threshold with the largest impurity decrease.
The CART book was first published by Wadsworth in 1984. The record used in this lesson to verify the title and authors is the CRC reprint (Crossref dates the reprint at 2017-10-19, DOI 10.1201/9781315139470); the year of first publication remains 1984.
Overfitting and cost-complexity pruning
An unconstrained tree can grow until almost every training example has its own leaf. scikit-learn writes minimal cost-complexity pruning as follows (the documentation points to Chapter 3 of the CART book):
R_α(T) = R(T) + α |T̃|
Here |T̃| is the number of terminal nodes (leaves). In the traditional account R(T) is the total misclassification rate of the leaves; scikit-learn uses the total sample-weighted impurity instead. Larger α ≥ 0 favours a smaller tree. The parameter name is ccp_alpha. In practice, pre-pruning parameters such as max_depth and min_samples_leaf are also common.
The experiment uses California Housing: 20,640 examples and eight features (MedInc, HouseAge, AveRooms, AveBedrms, Population, AveOccup, Latitude, Longitude). The target is the median house value of a block group, in units of US$100,000. With test_size=0.2 and random_state=0 the split is 16,512 training rows and 4,128 test rows. The target has mean 2.0686, standard deviation 1.1539 and range 0.15 to 5.00. Training DecisionTreeRegressor at several values of max_depth (all other arguments left at their defaults) gives:
| Max depth | Leaves | Train RMSE | Test RMSE |
|---|---|---|---|
| 1 | 2 | 0.9569 | 0.9660 |
| 4 | 16 | 0.7391 | 0.7726 |
| 8 | 236 | 0.5729 | 0.6679 |
| 9 | 428 | 0.5254 | 0.6568 |
| 12 | 1,895 | 0.3696 | 0.6714 |
| 16 | 6,874 | 0.1746 | 0.7175 |
| Unconstrained | 15,834 | 0.0000 | 0.7312 |
Test RMSE is lowest at depth 9 (0.6568). Beyond that point the training error keeps falling while the test error rises. With no depth limit the tree has 15,834 leaves, close to the 16,512 training rows; the training RMSE is 0 and the test RMSE rises to 0.7312. That is a typical overfit.
Standardisation usually leaves the predictions unchanged
The scikit-learn documentation lists “little data preparation; other methods often require normalisation” among the advantages of decision trees. The reason is that a split tests x_j ≤ t. After the linear map z_j = (x_j − μ_j) / σ_j the threshold becomes t' = (t − μ_j) / σ_j, and each sample still falls on the same side.
With the same random seed and max_depth=4, a regressor trained on the raw features and one trained on StandardScaler features used the same split features, both had 16 leaves, the test predictions had a maximum absolute difference of 0, and both had a test RMSE of 0.772620. The thresholds match (t − μ) / σ to within floating-point error. Standardising features for a tree is therefore usually unnecessary, and it usually does not help; if a pipeline already contains a scaler, it generally will not change this tree’s predictions either.
Bagging and random forests
A deep tree has high variance. Breiman’s bagging (bootstrap aggregating, 1996) draws bootstrap samples of the training set, fits a model on each sample, and averages the predictions (regression) or takes a vote (classification). For a bootstrap sample of size n, the probability that any given training point is left out is (1 − 1/n)^n. On this lesson’s training set, n = 16,512, that probability is 0.3679, which equals 1/e ≈ 0.3679. The left-out points are the out-of-bag (OOB) sample and can be used to evaluate the model without a separate validation set.
Breiman’s random forests (2001) add a second source of randomness on top of bagging: at each node the search for a split is restricted to a random subset of the features, whose size is controlled by max_features. The scikit-learn ensemble guide states that bootstrapping the samples and randomly selecting features at each split are there to reduce the variance of the forest estimator. The less correlated the trees, the more the average reduces variance.
In this lesson, a RandomForestRegressor with 200 trees and max_features="sqrt" has a test RMSE of 0.4875 and a test R² of 0.8177. With oob_score=True, the OOB R² is also 0.8177. The agreement to four decimal places is a measurement on this split, not a general fact. OOB remains a useful approximation; scikit-learn’s notes on OOB estimates for gradient boosting also warn that they tend to be pessimistic, and that cross-validation should be preferred when it is affordable.
AdaBoost and gradient boosting
Boosting runs in the opposite direction from bagging: models are added one after another, and later models concentrate on what the current ensemble has not yet fitted.
AdaBoost, by Freund and Schapire (1997), was an early practical boosting algorithm. It trains a weak classifier (for example a very shallow tree), raises the weights of the examples it gets wrong, trains the next classifier, and finally takes a weighted vote. A random forest averages many trees in parallel; AdaBoost chains weak learners and weights them.
Friedman (2001) writes boosting as gradient descent in function space. If the current model is F_{t−1}, the tree at step t is fitted to the negative gradient of the loss with respect to the current prediction. When the loss is squared error, that negative gradient is the residual y − F_{t−1}(x). The new tree’s output is scaled by a small learning rate (shrinkage) before it is added, so that a single step cannot move too far. scikit-learn’s GradientBoostingRegressor, and later XGBoost and LightGBM, are built on this framework. Friedman (2002) also proposed stochastic gradient boosting: each round uses only a subset of the training examples (the documentation’s typical value is 0.5, drawn without replacement) and may also subsample features.
XGBoost: a regularised objective and second-order gain
Chen and Guestrin (2016) presented XGBoost as a scalable tree-boosting system at KDD 2016 (arXiv:1603.02754; conference DOI 10.1145/2939672.2939785). The official tutorial “Introduction to Boosted Trees” writes the objective as a training loss plus a regulariser:
obj(θ) = L(θ) + Ω(θ)
Ω(f) = γ T + (1/2) λ ∑_{j=1}^{T} w_j²
T is the number of leaves and w_j is the value of leaf j. L may be squared error, logistic loss, or another loss. Training is additive: each step learns one new tree. For a general loss the tutorial expands L to second order in a Taylor expansion and writes the step-t objective in terms of the first derivative g_i and the second derivative h_i. After summing the g_i and h_i that fall into a leaf as G and H, the gain from splitting one leaf into a left child and a right child is:
Gain = (1/2) [ G_L² / (H_L + λ) + G_R² / (H_R + λ) − (G_L + G_R)² / (H_L + H_R + λ) ] − γ
The four terms are the score of the new left leaf, the score of the new right leaf, the score of the original leaf, and the regularisation penalty for the extra leaf. If the gain is smaller than γ, the split does not reduce the objective and should be refused. Whether to split is then part of the objective, rather than a separate heuristic.
The paper’s abstract also proposes a sparsity-aware algorithm for sparse data (missing values can follow a default direction) and a weighted quantile sketch for proposing approximate split points. It discusses cache access, compression and sharding so that the system can handle larger data with fewer resources. The learning rate (shrinkage) and column subsampling are further regularisers. The example in this lesson uses tree_method="hist" (histogram approximate splitting), n_estimators=300, learning_rate=0.1 and max_depth=6.
LightGBM: histograms, leaf-wise growth, GOSS and EFB
LightGBM, by Ke, Meng, Finley, Wang, Chen, Ma, Ye and Liu (NeurIPS 2017), addresses the fact that conventional GBDT still scans all instances for every feature when it estimates split gain, which is costly in high dimension and on large samples. The paper introduces two techniques:
- GOSS (Gradient-based One-Side Sampling): keep the examples with large gradients and subsample those with small gradients, so that gain can be estimated from fewer examples.
- EFB (Exclusive Feature Bundling): bundle mutually exclusive features that rarely take non-zero values at the same time, which reduces the effective number of features. The paper proves that finding an optimal bundling is NP-hard, but a greedy algorithm can give a good approximation.
On several public data sets the paper reports a training speed-up of more than 20 times relative to conventional GBDT, with almost the same accuracy. Those figures are the paper’s results, not a reproduction in this lesson.
The official documentation emphasises two further implementation choices. A histogram algorithm buckets continuous features, which cuts the cost and memory of evaluating split gain. Trees grow leaf-wise (best-first) by default: each step expands only the current highest-gain leaf, rather than a whole level. Leaf-wise growth often reduces the loss faster, but it can also grow a single path too deep, so the documentation treats num_leaves and min_data_in_leaf as the main controls against overfitting. Categorical features can be split optimally without one-hot encoding. The example in this lesson uses n_estimators=300, learning_rate=0.1 and num_leaves=31 (the library’s default leaf count).
A comparison on the same split
The table below is a single comparison on the California Housing split above, with fixed hyperparameters and no grid search. It is meant to show how a single tree, bagging and boosting behave on the same data; it is not a claim that one implementation is always best. RMSE and MAE are in units of US$100,000.
| Model | Train RMSE | Test RMSE | Test MAE | Test R² |
|---|---|---|---|---|
| Decision tree (unconstrained) | 0.0000 | 0.7312 | 0.4695 | 0.5900 |
Decision tree (max_depth=8) |
0.5729 | 0.6679 | 0.4662 | 0.6579 |
Random forest (200 trees, max_features=sqrt) |
0.1825 | 0.4875 | 0.3303 | 0.8177 |
| scikit-learn gradient boosting (200 trees, learning rate 0.1, depth 3) | 0.4712 | 0.5053 | 0.3489 | 0.8042 |
| XGBoost (300 trees, learning rate 0.1, depth 6) | 0.2703 | 0.4430 | 0.2926 | 0.8495 |
LightGBM (300 trees, learning rate 0.1, num_leaves=31) |
0.3057 | 0.4387 | 0.2931 | 0.8524 |
A depth-limited tree already beats the unpruned tree on the test set, but it remains well behind the forest and the boosted models. The random forest brings test RMSE down from about 0.73 to about 0.49. With the settings in this lesson, LightGBM has a test RMSE of 0.4387 and XGBoost 0.4430; the two are close. Training times depend on the machine. In this run with three threads, the random forest took about 2.0 seconds, XGBoost about 0.27 seconds and LightGBM about 0.18 seconds; those figures are only a reference on the same machine.
Explaining the model with SHAP and permutation importance
The unit project asks for a comparison of a single tree, a random forest and XGBoost on the same data, and an explanation of the best model. Under the settings above, LightGBM has the lowest test RMSE (0.4387), so the explanation below is for that model. If the hyperparameters change, the best model may be XGBoost or another implementation; the steps stay the same.
Lundberg and Lee (2017) proposed SHAP, which decomposes a model prediction into feature contributions that satisfy a set of axioms consistent with Shapley values in cooperative game theory. In the official implementation, TreeExplainer provides an efficient algorithm for tree models. This lesson draws 400 test rows without replacement and reports mean(|SHAP|) for each feature. Permutation importance follows the scikit-learn documentation: shuffle one column and record the change in a chosen metric. The scoring rule here is neg_root_mean_squared_error, so the means in the table are the increase in test RMSE after that feature is shuffled, averaged over 10 repeats.
| Feature | mean(|SHAP|) | Permutation importance (ΔRMSE) | |---|---|---| | Latitude | 0.4544 | 0.8057 ± 0.0098 | | MedInc | 0.3869 | 0.3908 ± 0.0094 | | Longitude | 0.3631 | 0.7116 ± 0.0058 | | AveOccup | 0.2095 | 0.1823 ± 0.0084 | | AveRooms | 0.1299 | 0.1220 ± 0.0047 | | HouseAge | 0.0500 | 0.0554 ± 0.0038 | | Population | 0.0246 | 0.0151 ± 0.0015 | | AveBedrms | 0.0239 | 0.0147 ± 0.0018 |
Both methods place latitude, longitude and median income (MedInc) at the top, which matches the fact that California house prices are sensitive to location and income. The internal ranking is not the same: in mean absolute SHAP, MedInc ranks above Longitude; in permutation importance, Longitude ranks above MedInc. That is not a contradiction. SHAP describes the average magnitude of a feature’s contribution to individual predictions under the fitted model; permutation importance describes how much test RMSE rises when the link between that feature and the target is broken. A single importance measure should not be used on its own, and feature importance should not be read as a causal claim.
Runnable example
The following code was run on scikit-learn 1.9.1, XGBoost 3.4.1, LightGBM 4.7.0 and SHAP 0.54.1. The numbers match the text above. The full script, including all twenty depth settings and the threshold comparison, is at research/ai-algorithms/_work/daily/2026-11-22/tree_demo.py. Setting OMP_NUM_THREADS=3 is recommended.
import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
from sklearn.inspection import permutation_importance
from xgboost import XGBRegressor
from lightgbm import LGBMRegressor
import shap
# 1) Toy split: balanced two-class root
x = np.array([1, 1, 2, 2, 3, 3, 8, 8, 9, 9, 10, 10], dtype=float)
y = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0])
def gini(c):
p = c / c.sum()
return float(np.sum(p * (1 - p)))
def entropy(c):
p = c[c > 0] / c.sum()
return float(-np.sum(p * np.log2(p)))
root = np.bincount(y)
print("root", root, "Gini", round(gini(root), 4), "entropy", round(entropy(root), 4))
for t in (1.5, 2.5, 5.5, 8.5):
left, right = y[x <= t], y[x > t]
lc, rc = np.bincount(left, minlength=2), np.bincount(right, minlength=2)
n = len(y)
g = (len(left) * gini(lc) + len(right) * gini(rc)) / n
e = (len(left) * entropy(lc) + len(right) * entropy(rc)) / n
print(t, "dGini", round(gini(root) - g, 4), "IG", round(entropy(root) - e, 4))
# 2) California Housing comparison
data = fetch_california_housing()
X_tr, X_te, y_tr, y_te = train_test_split(
data.data, data.target, test_size=0.2, random_state=0
)
models = {
"tree": DecisionTreeRegressor(random_state=0),
"tree_d8": DecisionTreeRegressor(max_depth=8, random_state=0),
"rf": RandomForestRegressor(
n_estimators=200, max_features="sqrt", random_state=0, n_jobs=3, oob_score=True
),
"gbm": GradientBoostingRegressor(
n_estimators=200, learning_rate=0.1, max_depth=3, random_state=0
),
"xgb": XGBRegressor(
n_estimators=300, learning_rate=0.1, max_depth=6,
tree_method="hist", n_jobs=3, random_state=0, verbosity=0,
),
"lgbm": LGBMRegressor(
n_estimators=300, learning_rate=0.1, num_leaves=31,
n_jobs=3, random_state=0, verbosity=-1,
),
}
best_name, best_est, best_rmse = None, None, None
for name, est in models.items():
est.fit(X_tr, y_tr)
pred = est.predict(X_te)
rmse = mean_squared_error(y_te, pred) ** 0.5
print(name, "test_RMSE", round(rmse, 4), "MAE", round(mean_absolute_error(y_te, pred), 4),
"R2", round(r2_score(y_te, pred), 4))
if best_rmse is None or rmse < best_rmse:
best_name, best_est, best_rmse = name, est, rmse
print("best", best_name, best_rmse)
# 3) SHAP and permutation importance (lowest test RMSE)
idx = np.random.default_rng(0).choice(len(X_te), size=400, replace=False)
sv = shap.TreeExplainer(best_est).shap_values(X_te[idx])
print("mean|SHAP|", dict(zip(data.feature_names, np.mean(np.abs(sv), axis=0).round(4))))
perm = permutation_importance(
best_est, X_te, y_te, n_repeats=10, random_state=0, n_jobs=3,
scoring="neg_root_mean_squared_error",
)
print("perm", dict(zip(data.feature_names, perm.importances_mean.round(4))))
Key measured outputs: root Gini 0.5000, entropy 1.0000; at t = 2.5 the Gini gain is 0.2500 and the information gain is 0.4591, both higher than 0.2222 and 0.3500 at t = 5.5. Test RMSE: unconstrained tree 0.7312, depth-8 tree 0.6679, random forest 0.4875 (OOB R² 0.8177), scikit-learn gradient boosting 0.5053, XGBoost 0.4430, LightGBM 0.4387. For LightGBM, the top three mean(|SHAP|) values are Latitude 0.4544, MedInc 0.3869 and Longitude 0.3631; the top three permutation importances are Latitude 0.8057, Longitude 0.7116 and MedInc 0.3908.
Exercises
- Unit project. On the same data set, compare a single decision tree, a random forest and XGBoost (LightGBM may be added), record the test error, and explain the model with the lowest test error using SHAP or permutation importance. You may reuse this lesson’s California Housing split or use your own tabular data. Fix the random seed and write down every hyperparameter.
- Complete the XGBoost exercise in Kaggle Learn: Intermediate Machine Learning. Vary
n_estimatorsand the learning rate and watch how the validation error changes. - Run the ensemble examples in the official scikit-learn example gallery, compare random forests, gradient boosting and AdaBoost, and change
max_depth,n_estimatorsorlearning_rate. - Read the XGBoost tutorial Introduction to Boosted Trees and check the gain formula by hand on a tree of depth 1. Then, using LightGBM Parameters Tuning, explain why
num_leaves=63is not the same as a complete binary tree withmax_depth=6.
Suggested reading order
Start with the mathematical formulation and the CART subsection in the scikit-learn decision-tree guide, and with the random-forest and gradient-boosting subsections of the ensemble guide, to fix the contrast between a single tree, bagging and boosting. For a statistical-learning account, see the tree and ensemble chapters of the free textbook An Introduction to Statistical Learning and the Google Decision Forests course. For implementation details, read the XGBoost tutorial and LightGBM Features. For explanation, read the SHAP documentation and the paper by Lundberg and Lee (2017). A natural next step in the same stage is linear models and support vector machines, or Unsupervised Learning: Clustering, Dimensionality Reduction and EM.
FAQ
Why is a random forest usually more stable than a single tree?
A deep tree has high variance: its structure moves around with small changes in the training sample. A random forest fits each tree on a bootstrap sample (bagging) and, at every node, searches only a random subset of features, which reduces correlation among the trees. Averaging or voting then cancels much of the remaining error. In this lesson’s California Housing experiment, the unpruned tree had a test RMSE of 0.7312, and a forest of 200 trees with max_features=sqrt had a test RMSE of 0.4875.
What does each round of gradient boosting fit?
In Friedman’s (2001) gradient boosting, each round takes a step in function space along the negative gradient of the loss with respect to the current prediction. When the loss is squared error, that negative gradient is the residual. The new tree’s output is scaled by a small learning rate (shrinkage) before it is added. XGBoost additionally uses second derivatives (a Newton step) to set leaf values and to compute split gain.
Do tree models need feature standardisation?
Usually not. A split tests x_j ≤ t, so a monotone transformation or a standardisation of feature j does not change which side of the threshold a sample falls on. The scikit-learn decision-tree guide lists “little data preparation” as an advantage and notes that other methods often need normalisation. With the same random seed and max_depth=4, a regressor trained on raw features and one trained on StandardScaler features produced identical test predictions (maximum absolute difference 0) and the same test RMSE of 0.772620.
When does XGBoost refuse a split?
The official tutorial writes the split gain as the score of the new left leaf plus the score of the new right leaf, minus the score of the original leaf, minus gamma. Gamma is the penalty for one extra leaf in the complexity term Ω(f) = γT + (1/2)λ∑w_j². If the gain is smaller than γ, the split does not reduce the objective and should not be made.
Why does LightGBM treat num_leaves and min_data_in_leaf as the key parameters?
The official documentation states that LightGBM grows trees leaf-wise (best-first) by default: each step expands the leaf with the current largest gain, rather than growing a whole level at a time. That often reaches a lower loss sooner, but it can also grow a single path very deep. num_leaves caps the number of leaves and min_data_in_leaf prevents tiny leaves. Setting either of them too large tends to overfit.