skip to content

Trees, Forests, and Boosting

You will learn why tree ensembles dominate tabular ML: bagging cuts variance, boosting cuts bias, and a regularized objective made GBDT the default. 'Random forest vs boosting' is a staple screen.

on this pageshow

explore

questions

page 1 of 2

Why does a decision tree approximate a diagonal decision boundary with a staircase?

level: juniorimportance: must knowfreq 72%

answer

  1. one feature per question
  2. cuts perpendicular to an axis
  3. leaves are boxes, never slanted
  4. steps get finer, never tilt
  5. a summed feature turns it into one cut

basics

~20 s

Every split tests one feature against one threshold, so each cut is a line perpendicular to one axis. A boundary that depends on two features jointly can only be tiled by many small axis-parallel steps.

solid answer

~40 s

A tree node asks a question of the form `feature <= threshold`, which is a cut perpendicular to that feature's axis. The regions it carves are therefore always axis-parallel boxes, and the boundary between them is made of horizontal and vertical pieces only. Suppose delivery eligibility is really `latitude + longitude <= c`, a 45-degree line: the tree has to tile the eligible side with rectangles, so it spends one split per step, and it needs the most steps exactly where data is scarcest, right along the boundary. More depth makes the steps finer but never tilts them, and rescaling the features changes nothing at all. The effective fix is a feature: hand the tree `latitude + longitude` as a column and a single split reproduces the rule exactly.

go deeper

for a junior

Be ready to state that each node tests one feature against one threshold, so the regions are axis-parallel boxes, and to sketch a staircase hugging a 45-degree line.

for a middle

Explain the cost mechanics: one split per step, error concentrated in the triangles along the boundary, depth growing where data is thinnest, and why scaling changes nothing.

for a senior

Show the diagnosis-to-fix path: spot that a rule is a sum or ratio, add it as a feature, and demonstrate that the tree becomes shallower and its extracted rules readable.

for a principal

Own the framing question of whether the feature space is the right coordinate system for the problem at all, and weigh engineered combinations against oblique splits or a different model family.

## What "axis-aligned" means A CART-style decision tree grows by asking, at each internal node, a question of exactly one shape: `feature_j <= t`. One feature, one threshold, one comparison. Geometrically that question is a hyperplane perpendicular to the j-th coordinate axis. Applying such a question recursively partitions the input space into **hyperrectangles** — boxes whose faces are all parallel to the axes. In two dimensions each leaf is a rectangle (possibly unbounded), and the model's decision boundary is a union of horizontal and vertical segments. It can never contain a slanted edge, because no node is allowed to ask about two features at once. ## Where the staircase comes from Take a delivery-zone rule where a customer is eligible when `latitude + longitude <= c`. In the latitude-longitude plane that is a single straight line at 45 degrees. Neither feature alone tells you the answer: for any fixed latitude there is a longitude cutoff, and that cutoff moves as latitude moves. The tree can only approximate this by chopping latitude into bands and, inside each band, picking a longitude cutoff — which is precisely a staircase hugging the diagonal. The cost has a shape worth internalising. Each step costs a split, and the misclassified area is the set of little triangles between the true line and the step edges. Halving the width of the steps roughly halves that error area but doubles the number of leaves. Meanwhile every threshold has to be estimated from the rows near it, and the rows near the boundary are the scarce, ambiguous ones. So the tree is most data-hungry exactly where it has the least usable signal — that is why a diagonal boundary shows up as a deep, jagged, sample-sensitive region of the model rather than as an outright failure. ## Consequences you can name in an interview 1. **Sample cost.** Accuracy near the boundary improves only as fast as you can afford new splits, and each split needs rows. 2. **Jagged behaviour.** Two customers a hundred metres apart, on either side of one step, get opposite decisions for no reason a domain expert would accept. 3. **Unreadable explanations.** The extracted rules read as an arbitrary list of coordinate thresholds when the real rule is a one-line sum. 4. **Ensembles do not remove it.** Combining many axis-aligned trees produces a finer, smoother-looking staircase — the steps shrink, they do not tilt. ## Scale invariance is not rotation invariance A tree compares a value to a threshold, so it only uses the **order** of the values, not their spacing. Apply any strictly increasing transform to a single feature — multiply by 1000, switch from metres to feet, take a log of a positive quantity — and every threshold maps across one-for-one. The tree structure and every prediction are unchanged. That is why standardising features does nothing for a tree. Rotation is a different operation: it mixes features. Rotate two vibration-sensor axes by 45 degrees and the data cloud is geometrically identical, but the informative direction now lies diagonally in the new coordinates. The tree that used one clean cut now needs a staircase, and its node count explodes for the same accuracy; a linear model fits the rotated data just as well as the original, with rotated coefficients. Trees are invariant to monotone transforms of individual features, and sensitive to linear combinations of them. Candidates who have half-memorised "trees do not care about scaling" usually over-generalise it into "trees do not care about the coordinate system," which is the opposite of true. ## What actually helps - **Engineer the combination.** If you suspect a sum, difference, or ratio drives the outcome, add it as a column. One split on `latitude + longitude` reproduces the diagonal exactly, and the model gets shallower, more stable, and more readable at once. This is the highest-value move by a wide margin. - **Oblique (multivariate) trees.** These split on a linear combination of several features, so a node can express a slanted cut directly. They are more expressive but costlier to fit and harder to explain. - **Pick a different family.** If the true structure is a smooth or rotated boundary, a model whose boundary is naturally oblique will need far less data. - **Or accept it.** Many real tabular rules genuinely are axis-aligned — a price threshold, an age cutoff, a sensor limit, a policy band. That is a large part of why trees do so well on tabular business data; the staircase is only a liability when the truth is diagonal. ## What does not help Deeper trees give finer steps, not slanted ones. Feature scaling has literally no effect. More data shrinks the steps but leaves the staircase in place. Recognising this trio as non-fixes is what separates a real answer from a recited one.

  • Would standardising latitude and longitude help the tree find that diagonal boundary?
    No. A split only compares a value to a threshold, so it depends on the order of values, not their units or spread. Any strictly increasing rescaling maps each threshold one-for-one and leaves the fitted tree and its predictions identical. Standardisation matters for distance-based and penalised models, not for this one.
  • What single engineered feature would let one split capture the rule?
    The sum itself: add a column equal to latitude plus longitude, and the rule becomes a threshold on that one column, which is exactly what a node can express. The same trick applies to differences (price minus cost), ratios (debt to income), and any combination you can state in domain terms.
  • Does axis alignment also make a tree rotation-invariant?
    No, and this is the common over-generalisation. Trees are invariant to monotone transforms of a single feature, but rotating the axes mixes features. Rotate two sensor channels by 45 degrees and the same signal now needs a staircase of many nodes instead of one cut, while a linear model's fit is unaffected.

It is like drawing a diagonal line on graph paper by filling in whole squares: you can hug the line as closely as you like by using smaller squares, but the edge is always made of corners.

saying these in an interview costs you the question

  • Claims a deeper tree eventually produces a truly diagonal boundary
  • Says standardising the features would fix the staircase
  • Believes one node can test two features at once
  • Confuses scale invariance with invariance to rotating the axes
  • Assumes more training data removes the steps rather than shrinking them

context

open as a page

What is bagging, and why does averaging bootstrap-trained models cut variance but not bias?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Bagging trains many copies of one model on bootstrap resamples of the training rows, then averages their predictions. Averaging cancels the errors that differ from copy to copy, cutting variance; the systematic error every copy shares survives, so bias stays.

open as a page

How does gradient boosting build a regression model stage by stage?

level: juniorimportance: must knowfreq 78%

basics

~10 s

Gradient boosting starts from a single constant prediction, then repeatedly fits a shallow tree to the errors the model still makes and adds that tree to the running total. Earlier trees are never refitted.

open as a page

What is the difference between leaf-wise and level-wise tree growth in gradient boosting?

level: juniorimportance: must knowfreq 70%

basics

~20 s

Level-wise growth splits every leaf at the current depth before going deeper, producing balanced trees. Leaf-wise growth repeatedly splits whichever leaf anywhere in the tree promises the largest loss reduction, producing deeper, lopsided trees that fit harder and overfit sooner.

open as a page

Which growth-stopping limits keep a decision tree from splitting until every leaf is pure?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Four pre-pruning limits: a maximum tree depth, a minimum node size to split, a minimum number of samples per resulting leaf, and a minimum impurity decrease per split. Any split breaking one of them is refused.

open as a page

Can adding more trees to a random forest make it overfit the training data?

level: juniorimportance: must knowfreq 74%

basics

~20 s

No. The number of trees is a Monte Carlo averaging parameter, so error converges to a limit and flattens rather than degrading. Overfitting in a forest comes from how deep and how pure the individual trees may grow.

open as a page

In gradient boosting, what does the learning rate do, and how does it trade against the number of rounds?

level: juniorimportance: must knowfreq 74%

basics

~20 s

The learning rate scales every tree's output before it is added to the ensemble. Shrinking it makes each round a smaller correction, so you need proportionally more rounds; roughly, learning rate times rounds sets how far the fit travels.

open as a page

How do Gini impurity and entropy differ as split criteria for a classification tree?

level: juniorimportance: must knowfreq 74%

basics

~20 s

Gini impurity is 1 - sum(p_i^2) and entropy is -sum(p_i * log2 p_i). Both are zero at a pure node and largest when classes are evenly mixed, and they rank splits so similarly that the choice rarely changes the tree.

open as a page

In AdaBoost, what happens to the example weights and the learner's vote weight after each round?

level: middleimportance: must knowfreq 70%

basics

~20 s

AdaBoost scales misclassified examples' weights up and correct ones down, then renormalises, so the next weak learner targets current mistakes. That learner's vote weight is 0.5 * ln((1 - e) / e), where e is its weighted error.

open as a page

Why does a regression tree flatten out when asked to predict beyond its training range?

level: middleimportance: must knowfreq 58%

basics

~20 s

A regression tree's leaves store constants, usually the mean target of the training rows that land there. Anything past the largest split threshold falls into the same edge leaf, so the prediction stops moving and stays inside the range of training targets.

open as a page

How does histogram-based split finding speed up training in a gradient-boosted tree?

level: middleimportance: must knowfreq 62%

basics

~20 s

Histogram-based split finding pre-bins each continuous feature into a few hundred buckets once, before training. Split scoring then scans a few hundred candidate cut points per feature instead of every sorted data value, and stores one byte per value.

open as a page

How is a random forest's built-in impurity importance computed for one feature?

level: middleimportance: must knowfreq 66%

basics

~20 s

Impurity importance sums, for every split that uses the feature, the drop in node impurity weighted by the fraction of training rows reaching that node. The totals are combined across the forest's trees and normalised to sum to one.

open as a page

How does an ordered target statistic stop a row's own label from leaking into its encoding?

level: middleimportance: must knowfreq 60%

basics

~20 s

An ordered target statistic encodes each row using only the rows that precede it in a random permutation and share its category. The row's own label never enters its own encoding, so the feature cannot cheat on training data.

open as a page

How does cost-complexity pruning use alpha to shrink a fully grown decision tree?

level: middleimportance: must knowfreq 55%

basics

~20 s

Cost-complexity pruning scores a tree as training error plus alpha times its leaf count, then collapses the subtree with the smallest error cost per leaf removed. Larger alpha yields a smaller tree, and alpha is chosen by cross-validation.

open as a page

What does a random forest add on top of bagged decision trees, and why does it help?

level: middleimportance: must knowfreq 82%

basics

~20 s

A random forest restricts every split to a random subset of the features. That stops one strong predictor dominating every tree, so the trees are less correlated — and correlation between trees is what limits how much variance averaging can remove.

open as a page

In gradient boosting, how does a second-order Taylor expansion set each leaf's weight?

level: middleimportance: must knowfreq 62%

basics

~20 s

Expanding the loss to second order around the current predictions turns each leaf into a one-variable quadratic in its output. Minimising that quadratic gives the leaf weight -G/(H+lambda): minus the summed gradients over the summed curvatures plus the penalty.

open as a page

Why must a stacking ensemble's meta-learner be trained on out-of-fold base-model predictions?

level: middleimportance: must knowfreq 68%

basics

~20 s

Base models memorise their own training rows, so in-sample predictions look far better than they ever will on new data. Out-of-fold predictions, where each row is scored by a model that never saw it, give the meta-learner honest inputs.

open as a page

When would you choose a random forest over gradient boosted trees on a tabular dataset?

level: middleimportance: must knowfreq 78%

basics

~20 s

Choose a random forest when tuning time is short and the data is small or noisy: its defaults sit close to its best and averaging dilutes bad rows. Choose gradient boosting when you can afford a search and need maximum accuracy.

open as a page

Why does mean impurity decrease rank a pure-noise, near-unique donor ID column third?

level: seniorimportance: must knowfreq 56%

basics

~20 s

A near-unique column offers thousands of candidate cut-points, so the greedy splitter can almost always find one that lowers training impurity by chance. Those spurious splits accumulate credit because impurity importance is measured on the training rows only.

open as a page

In AdaBoost, why is a one-split decision stump the standard weak learner?

level: juniorimportance: should knowfreq 50%

basics

~20 s

Boosting supplies accuracy through many rounds, so it needs a high-bias, low-variance base learner only slightly better than chance. A stump, one feature and one threshold, is the cheapest such learner and refits fast each reweighted pass.

open as a page

What is the difference between hard voting and soft voting in a classifier ensemble?

level: juniorimportance: should knowfreq 52%

basics

~10 s

Hard voting takes each model's predicted class label and picks the majority. Soft voting averages the models' predicted class probabilities and picks the highest average, so a confident model outweighs several hesitant ones.

open as a page

Why do boosted tree ensembles lead on heterogeneous tabular data?

level: juniorimportance: should knowfreq 55%

basics

~10 s

Tabular columns are heterogeneous, thresholded and interaction-heavy. Axis-aligned splits handle mixed units, categories and missing values with no scaling, and boosting's stage-wise fitting keeps adding capacity exactly where the ensemble is still wrong.

open as a page

Why can removing one training row change a decision tree's root split entirely?

level: middleimportance: should knowfreq 48%

basics

~20 s

Split choice is a greedy pick of the single best-scoring cut, and the top candidates are often nearly tied. A one-row change can flip which cut wins, and because the choice is at the root, every subtree below is rebuilt on a different partition.

open as a page

Why does a bootstrap resample of n rows contain only about 63% of the distinct original rows?

level: middleimportance: should knowfreq 46%

basics

~20 s

Drawing n rows with replacement, a given row is missed on every draw with probability (1 - 1/n)^n, which converges to 1/e, about 0.368. So roughly 63.2% of the distinct rows land in-bag and 36.8% are out-of-bag.

open as a page

Why does gradient boosting fit pseudo-residuals instead of plain residuals?

level: middleimportance: should knowfreq 58%

basics

~20 s

Each tree fits the negative gradient of the loss at the current prediction, not the raw error. For squared error that equals the plain residual; for log loss it is the label minus the predicted probability.

open as a page

In gradient boosting, how do total-gain and split-count feature importance differ?

level: middleimportance: should knowfreq 44%

basics

~20 s

Total gain sums the objective reduction every split on the feature achieved; split count only counts how many nodes used the feature, treating a decisive root split and a trivial deep one as equal. They routinely rank the same model's features differently.

open as a page

In gradient boosting, what do row subsampling and column subsampling per round buy you?

level: middleimportance: should knowfreq 46%

basics

~20 s

Fitting each round's tree on a random fraction of rows and columns decorrelates successive trees, adds a regularising noise to the gradient estimate, and cuts per-round cost. It usually validates better than the full-data fit, until the subsample is so small the fit turns unstable.

open as a page

How does a regression tree decide where to split when the target is continuous?

level: middleimportance: should knowfreq 56%

basics

~20 s

A regression tree scores each candidate split by the sample-weighted variance of its two children and keeps the largest variance reduction. Each leaf then predicts the mean of the training targets that land in it.

open as a page

Why does AdaBoost's exponential loss make it fragile to mislabelled rows and outliers?

level: seniorimportance: should knowfreq 55%

basics

~20 s

Exponential loss penalises a wrong prediction exponentially in how wrong it is, so a mislabelled row that can never be fit gains weight every round. Tens of rounds later a few such rows can own most of the distribution.

open as a page

showing 1–30 of 52