The interview question

“How do decision trees, random forests, and gradient boosting differ?”

A decision tree partitions feature space through a sequence of tests. Each leaf produces a prediction. Ensembles combine multiple trees, but the way those trees are trained changes the behavior of the resulting model.

01. Explain one split

For classification, a tree may select a split that reduces weighted class impurity. With Gini impurity, a node has impurity 1 − Σpₖ², where pₖ is the class proportion.

Imagine a node with ten examples: five positives and five negatives. Its Gini impurity is 0.5. A split creates two equally sized children with class counts (4,1) and (1,4). Each child has impurity 0.32, so the weighted reduction is 0.18.

This does not prove the split will generalize. Deep trees can isolate individual examples. Control depth, minimum leaf size, or pruning with validation data.

02. Compare the ensembles

ApproachHow trees are fitMain trade-off
Single treeOne sequence of partitions.Simple to inspect when small; can be unstable.
Random forestMany randomized trees, typically using bootstrapped rows and feature subsampling.Averaging can reduce variance; inference and memory grow with the ensemble.
Gradient boostingTrees are added sequentially to improve the current objective.Strong interaction modeling; requires careful complexity and learning-rate choices.

For squared-error boosting, a new tree can fit residuals. For other differentiable losses, the more general idea is fitting a direction related to the negative loss gradient. Saying every boosting algorithm simply predicts raw residuals is too broad.

03. Trace a boosting update

In a toy regression task, the current prediction is 10 and the target is 14. A new tree predicts a correction of 3. With a shrinkage rate of 0.1, the updated prediction becomes 10 + 0.1 × 3 = 10.3.

Many small steps can be more controlled than a few large corrections, but a lower learning rate may require more trees. Evaluate the combination of tree complexity, number of iterations, and learning rate rather than tuning them in isolation.

04. Make a production choice

Tree ensembles are useful candidates for tabular problems such as fraud detection. Compare them with a simpler linear baseline under the same time split, feature availability, and action policy.

Tree splits usually do not require standardized numerical scales in the way gradient-based linear training can. However, missing values and categorical inputs depend on the implementation; do not assume every tree library handles them natively.

Measure serving latency with the actual number and depth of trees. Check probability calibration separately from ranking. Feature-importance measures can be distorted by correlated features or cardinality, so do not interpret them as causal explanations.

05. Answer the follow-up

“Which always wins: random forest or boosting?”

Neither. Data size, noise, feature structure, tuning budget, latency, and evaluation setup determine the result. A fair baseline comparison is more useful than a universal ranking.

“Will more trees overfit?”

It depends on the ensemble and settings. Additional boosting iterations can overfit; use validation and early stopping. Forest averaging has different behavior and should not be equated with sequential boosting.

Self-review

Explain how averaging independently randomized trees differs from adding corrective trees. Then name one operational cost of each.

Sources & further reading

scikit-learn: ensemble methods covers forests and gradient boosting. Calculations above are original teaching examples.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.