A decision tree predicts by asking a sequence of yes/no questions about the features, and a forest or boosted ensemble averages or sums many such trees. Single trees are easy to read but unstable. Ensembles fix that and, on tabular data, are still the models I try first before touching a neural net. The page walks through how a split is chosen, why trees overfit, and how bagging and boosting attack the two halves of the bias-variance tradeoff.

A decision tree is a game of twenty questions that ends with an answer. Image: Rossc0827, CC BY-SA 4.0, via Wikimedia Commons.
Mental Model
- A tree partitions feature space into axis-aligned boxes and predicts a constant (class mix or mean) in each box.
- Training is greedy: at each node pick the single split that most reduces impurity, then recurse. There is no look-ahead.
- A deep tree has low bias and high variance. Bagging averages away variance. Boosting reduces bias by adding trees that correct the current errors.
- Random forests decorrelate their trees by also subsampling features, which makes averaging more effective.
- Gradient-boosted trees (XGBoost, LightGBM) are the strong default for tabular data.
1. Choosing a Split
At a node with class proportions , two standard impurity measures are
Both are 0 for a pure node and maximal for a uniform mix. A candidate split sends samples left and right, and its quality is the impurity decrease (information gain when using entropy):
The algorithm (CART) scans every feature and every threshold between sorted values and takes the best . For regression, the impurity is the variance of the targets in the node, and the prediction is their mean.
Worked example
A node holds 20 samples, 10 of each class. Parent: Gini , entropy bit.
Split A sends 10 samples left (8 positive, 2 negative) and 10 right (2 positive, 8 negative). Each child has Gini and entropy bits. The weighted Gini is , so , and the information gain is bits.
Split B sends 16 samples left (10 positive, 6 negative) and 4 right (all negative). Left Gini is and right is , so the weighted Gini is and . Left entropy is , weighted , gain bits.
Both criteria prefer A here. They do not always agree, but in practice the choice between Gini and entropy changes the trees very little.
A categorical feature can be split by subset or, more commonly in libraries, one-hot encoded. For continuous features with many values, histogram binning (section 5) makes the scan cheap.
2. Overfitting and Pruning
Grown until every leaf is pure, a tree memorizes the training set: zero training error, with leaves that hold one or two samples and predictions that swing with single points. Two families of controls:
- Pre-pruning limits growth: maximum depth, minimum samples per leaf or per split, minimum impurity decrease, maximum number of leaves.
- Post-pruning grows a large tree and then removes branches. Cost-complexity pruning minimizes , the training error plus times the leaf count, and chooses by cross-validation.
Even a pruned single tree is unstable: changing a few training points can change the root split and hence the whole structure. That instability is the variance that ensembles exploit. Trees also cannot extrapolate (a regression tree predicts a constant outside the training range) and they approximate diagonal boundaries with staircases.
3. Bagging and Random Forests
Bagging (bootstrap aggregation, Breiman) trains trees, each on a bootstrap sample of the training rows drawn with replacement, and averages the predictions (votes for classification). If each tree has variance and trees are correlated with pairwise correlation , the variance of the average is
More trees drive the second term to zero but cannot touch the first, so the remaining lever is lowering . A random forest does that by considering only a random subset of features at each split, commonly about for classification and for regression as starting points. Some trees are then forced to use weaker features, which makes them less alike.
Each bootstrap sample leaves out about of the rows. Predicting each row using only the trees that did not see it gives the out-of-bag (OOB) error, a built-in validation estimate with no separate hold-out and no extra training. Forests rarely overfit by adding trees, since more trees only reduce variance, though individual deep trees still can be noisy.
4. Boosting
Boosting builds trees sequentially, each concentrating on what the ensemble so far gets wrong. The learners are weak (shallow) so bias is the main enemy.
AdaBoost (Freund and Schapire) keeps a weight on every training sample. After fitting a weak learner such as a depth-1 stump, it computes the weighted error , gives the learner a vote , and multiplies the weights of misclassified samples up so the next learner focuses on them. The final prediction is the sign of the weighted vote.
Gradient boosting (Friedman) generalizes this to any differentiable loss. Start from a constant . At step , compute the negative gradient of the loss at each sample’s current prediction, fit a small tree to those values, and update
with a learning rate (shrinkage) around 0.01 to 0.3. For squared error the negative gradient is exactly the residual , so each tree is fit to the current mistakes. For log-loss it is . This is gradient descent in function space, with trees as the steps. Boosting can overfit if you add too many trees, so the number of rounds is tuned with a validation set and early stopping.
XGBoost (Chen and Guestrin, 2016) adds a second-order Taylor expansion of the loss, explicit regularization on leaf weights and tree size, and handling of missing values and sparse data. LightGBM (Ke et al., 2017) bins features into histograms, which makes split finding fast, and grows trees leaf-wise (always splitting the leaf with the largest gain) instead of level by level, which is faster but can overfit on small data unless the leaf count is limited. CatBoost handles categorical features specially. All three expose the same knobs: learning rate, number of trees, depth or leaves, row and column subsampling, and L1/L2 on leaf values.
5. Trees Versus Neural Nets on Tabular Data
On tabular data (mixed numeric and categorical columns, no spatial or sequential structure), well-tuned gradient-boosted trees remain a hard baseline to beat. Grinsztajn and colleagues (2022) benchmarked tree ensembles against neural networks on medium-sized tabular datasets and reported that trees stayed ahead, and attributed it to three properties: tabular targets are often irregular, many columns are uninformative, and the data is not rotation invariant (each column has its own meaning, while a standard MLP treats rotated feature axes as equivalent and trees do not). Trees also need little preprocessing, tolerate unscaled and heavy-tailed features, handle missing values, train in seconds on a CPU, and give feature importances.
Neural nets win when the data has structure to exploit, such as images, audio, text or graphs (Convolutional Networks, Attention and Transformers), when there is a very large amount of data, or when you need end-to-end learning of embeddings. A common practical pattern is to feed learned embeddings, or a few engineered features, into a gradient-boosted model.
Common mistake
Reading impurity-based feature importance as causal or unbiased. It favors high-cardinality and continuous features and is computed on training data. Permutation importance on a held-out set is a safer default.
Related
- Generalization and Regularization: the bias-variance view behind bagging versus boosting
- Evaluation Metrics: choosing the score for imbalanced tabular problems
- Gradient Descent and Optimizers: gradient boosting is the same descent, taken in function space
- Linear and Logistic Regression: the baseline to compare against before using trees
- MLP L13: Explainable AI: interpreting tree models with importances and attributions
- Foundation Models L02: ML Basics: where classic models fit among neural ones