Tutorials › Exam PA - Predictive Analytics › Tree Depth And Interaction Order

Exam PA · Gradient Boosting and Tuning · Tutorial 560 of 966

Tree Depth And Interaction Order

Learn to interpret tree depth as a limit on the predictors that can interact along a path, and see what that limit means for boosted models.

Advanced 10 min read

What You'll Learn

  • Define tree depth by the maximum number of split decisions from root to leaf
  • Explain why boosted stumps create additive predictor effects
  • Identify the interaction orders a depth-limited tree can represent
  • Compare shallow and deeper trees using squared-error examples
  • Recognize when predictor engineering changes what a depth limit implies

Why Tree Depth Matters

In gradient boosting, each new tree adds a correction to the model built so far. The maximum depth of those trees controls how many split decisions can be made along a path from the root to a terminal leaf. That limits how many predictors can jointly determine a correction in a particular region of the predictor space.

A depth limit is therefore more than a setting for making trees smaller. It constrains the kinds of patterns the boosted model can express. Shallow trees tend to capture simple effects; deeper trees can represent more complex combinations. But greater depth does not guarantee better predictions: it can also let the model fit noise. The focus here is on what depth permits, not on selecting the best depth for a particular data set.

Definition: A tree's depth is the largest number of split decisions on any path from its root to a terminal leaf. Under this convention, a tree with one split on every path has depth 1. A depth-\(D\) tree can use at most \(D\) predictors on any one path, and therefore can represent interactions of order at most \(D\) among the predictors used on that path. It need not use \(D\) distinct predictors, and it need not represent an interaction of order \(D\).

Terminology varies across software: a control described as a maximum number of leaves or terminal nodes is not the same thing as maximum depth. A binary tree of depth \(D\) can have at most \(2^D\) leaves, but it may have fewer. Check the implementation's definition before interpreting a control named “depth.”

Depth and the Form of a Boosted Model

A boosted model with \(M\) trees can be written as

$$ F_M(x)=F_0(x)+\eta\sum_{m=1}^{M}h_m(x), $$

where \(F_0\) is the initial prediction, \(h_m\) is the contribution from tree \(m\), and \(\eta\) is the learning rate. For a regression model using squared-error loss, a tree's terminal leaves typically provide corrections based on the observations assigned to each leaf. The particular fitting procedure may use residuals or another gradient quantity, but the depth restriction applies to the tree structure in either case.

A depth-1 tree is a stump: it makes one split and assigns a prediction to each side. Its contribution is a function of one predictor. A sum of stumps can give different, flexible effects for several predictors, but the contribution from one predictor does not depend on the value of another. In that sense, the model remains additive across predictors.

A depth-2 tree can split on one predictor and then split again on another predictor within a branch. The prediction can then depend jointly on the two predictors. A depth-3 tree can have paths involving three predictors, allowing a three-way interaction in the represented pattern. These are possibilities, not guarantees: a split may reuse a predictor, a branch may stop early, or the data may provide no useful evidence for the more complex split.

Maximum depthWhat a path can condition onMaximum interaction order available
1One split conditionOne predictor at a time; additive effects across stumps
2Up to two split conditionsPairwise interactions
3Up to three split conditionsThree-way interactions

The table describes an upper bound along a path, not a promise about every fitted model. Also, a tree can use different predictors in different branches. For example, a depth-2 tree might split on \(A\) at its root, then on \(B\) in one branch and \(C\) in the other. It can represent the pairwise combinations \(A\)-with-\(B\) and \(A\)-with-\(C\), even though three distinct predictors appear somewhere in the whole tree. No path conditions on all three.

Worked Examples

Worked Example: A Stump Cannot Capture an XOR Pattern

A hypothetical screening model uses two binary predictors, \(A\) and \(B\), and a binary response \(y\). The four equally weighted observations are:

\(A\)\(B\)\(y\)
000
011
101
110

Using squared error, compare a stump with a depth-2 tree. For a fitted constant in a leaf, the squared-error-minimizing prediction is the mean response in that leaf.

Stump split on \(A\). In the \(A=0\) group, the response mean is \((0+1)/2=0.5\). In the \(A=1\) group, it is \((1+0)/2=0.5\). The sum of squared errors is

$$ (0-0.5)^2+(1-0.5)^2+(1-0.5)^2+(0-0.5)^2=1. $$

Stump split on \(B\). Each \(B\) group also contains one 0 and one 1. Each leaf prediction is 0.5, so the sum of squared errors is again 1. The unsplit mean is 0.5 and has the same total squared error.

Depth-2 tree. Split first on \(A\), then split each resulting branch on \(B\). Each terminal leaf contains one observation, so its prediction is that observation's response. All four predictions are exact, and the sum of squared errors is 0.

Method and check. We compared the leaf means and summed squared errors for each partition. The deeper tree reduces training error from 1 to 0, as expected because its leaves distinguish all four predictor combinations. This does not show that a deeper tree will predict better on new observations.

Common mistake avoided. It is not enough to say “there are two predictors, so a stump can use both.” One stump makes only one split; its output depends on one predictor. A depth-2 tree can condition on the combination.

Worked Example: Comparing One- and Two-Split Partitions

A hypothetical portfolio study records two binary indicators, \(A\) and \(B\), and a continuous response \(y\). There are two observations in each predictor combination:

\(A\)\(B\)Observed responses
0010, 12
0114, 16
1020, 22
1140, 42

Fit empirical-mean predictions in the leaves and use the sum of squared errors to compare a split on \(A\) with a depth-2 tree that splits on \(A\) and then \(B\). No sampling distribution is assumed; this is a calculation on the stated observations.

Depth 1, split on \(A\). The \(A=0\) leaf mean is \((10+12+14+16)/4=13\). Its squared error is \((10-13)^2+(12-13)^2+(14-13)^2+(16-13)^2=9+1+1+9=20\). The \(A=1\) leaf mean is \((20+22+40+42)/4=31\). Its squared error is \((20-31)^2+(22-31)^2+(40-31)^2+(42-31)^2=121+81+81+121=404\). Thus the total is \(20+404=424\).

Depth 2, split on \(A\), then \(B\). The four cell means are 11, 15, 21, and 41, respectively. Within each cell, the two observations differ from their mean by \(-1\) and \(1\), giving squared error \(1+1=2\). Across four leaves, the total is \(4(2)=8\).

The depth-2 tree captures the difference in the effect of \(B\) across the values of \(A\). For \(A=0\), the change from \(B=0\) to \(B=1\) is \(15-11=4\). For \(A=1\), it is \(41-21=20\). The interaction contrast is \(11-15-21+41=16\), not zero.

Method and check. We used the mean in each leaf and calculated the residual sum of squares from the observations. The deeper partition has lower training error, \(8\) versus \(424\), and its split structure permits a pairwise interaction.

Common mistake avoided. A large reduction in training error is not proof of better generalization. It only describes these observations; assessing predictive performance requires validation on data not used to fit the tree.

Why the Interaction Limit Holds

A useful way to justify the depth rule is to examine the leaves. Each leaf corresponds to conditions imposed by the splits on the path leading to it. If that path has at most \(D\) splits, its region is defined using at most \(D\) split decisions and at most \(D\) distinct predictors. The tree's prediction is constant within that leaf. A tree can combine the leaf regions in a way that depends jointly on the predictors used along a path, but no individual path can condition on more predictors than its depth allows.

For depth 1, each tree's prediction depends on at most one predictor. Adding such tree contributions does not create a term that depends jointly on two predictors: the sum of functions of individual predictors is still additive. In the XOR example, any additive prediction has the form \(c+f(A)+g(B)\). Its mixed contrast must be zero:

$$ \begin{aligned} &[c+f(0)+g(0)]-[c+f(0)+g(1)]\\ &\quad-[c+f(1)+g(0)]+[c+f(1)+g(1)]=0. \end{aligned} $$

But the XOR responses have contrast \(0-1-1+0=-2\), not zero. Therefore no additive combination of stumps can reproduce those four responses exactly. A depth-2 tree can, because its path conditions distinguish the joint values of \(A\) and \(B\).

The same reasoning extends to higher orders: a sum of functions each depending on at most two predictors cannot represent every genuinely three-way pattern. Depth 3 makes such patterns available by permitting three predictors along a path. Availability is not the same as automatic inclusion: the fitting algorithm still has to choose useful splits.

Worked Example: A Three-Way Pattern Requires More Depth

Consider three binary predictors \(A\), \(B\), and \(C\), and let \(y=1\) when an odd number of predictors equal 1, and \(y=0\) otherwise. The eight response values are:

\(A\)\(B\)\(C\)\(y\)
0000
0011
0101
0110
1001
1010
1100
1111

A depth-3 tree can split successively on \(A\), \(B\), and \(C\). Each of its eight leaves then corresponds to one predictor combination, so its predictions equal the listed responses and its squared error is 0.

To see why depth-2 trees cannot represent this pattern exactly as a boosted sum, take the third-order contrast \(y_{111}-y_{110}-y_{101}-y_{011}+y_{100}+y_{010}+y_{001}-y_{000}\). For the table it equals \(1-0-0-0+1+1+1-0=4\). Any function omitting at least one of \(A\), \(B\), or \(C\) has a zero third-order contrast, because terms that differ only in the omitted predictor cancel. Every depth-2 tree contribution omits at least one predictor on each path; a sum of those contributions also has zero third-order contrast. It cannot equal this response pattern, whose contrast is 4.

Method and check. We used a depth-3 partition to fit the eight combinations, then used the third-order contrast to test whether depth-2 contributions could reproduce the pattern. The exact depth-3 fit has zero error, while the nonzero contrast rules out an exact depth-2 representation.

Common mistake avoided. A depth-2 tree may involve all three predictors across different branches, but that does not mean it can express a three-way interaction. The relevant limit is the number of predictors conditioned on along one path.

Interpretation and Practical Cautions

Depth is a structural capacity limit, not a label for the statistical importance of a predictor. A deeper model can express more complex patterns, but a fitted split is not evidence of causation. Nor does a depth-\(D\) model necessarily contain a \(D\)-way interaction: it may stop splitting early or repeatedly split on the same predictor.

The interpretation also depends on the available predictors. If a feature has already been engineered as a product or other combination of predictors, a stump can split on that feature and thereby use information that was jointly constructed elsewhere. In that situation, the stump is still a one-split tree, but its input is not an original single predictor. State what features are supplied when interpreting the effective interaction limit.

In practice, depth is one way to control the complexity of the individual learners in a boosted model. A shallow choice may be suitable when effects are expected to be mostly additive; deeper choices allow more interactions but can fit more local detail. The trade-off should be evaluated empirically rather than settled from training fit alone. This structural interpretation is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Key takeaway: Under the maximum-splits-per-path convention, depth \(D\) permits interactions among at most \(D\) predictors along a path. Stumps produce additive predictor effects; deeper trees make higher-order interactions possible, but do not guarantee them.

Check Your Understanding

For each problem, identify what the specified depth permits. Assume the stated predictors are the features supplied to the tree unless the question says otherwise.

  1. A boosted model uses only depth-1 trees on predictors \(U\) and \(V\). Can it represent an XOR response exactly as a sum of tree contributions? (Answer: No; each stump contributes a function of one predictor, so their sum is additive and cannot reproduce XOR.)
  2. A depth-2 tree splits first on \(R\), then on \(S\) in both branches. What is the maximum interaction order available on a path? (Answer: Two-way.)
  3. A depth-2 tree splits on \(R\) at the root, then on \(S\) in one branch and \(T\) in the other. Does this structure have a path containing all three predictors? (Answer: No; each path contains at most two predictors.)
  4. A depth-3 tree repeatedly splits on \(U\), with no other predictors used. What is the maximum interaction order actually present in this tree? (Answer: One predictor; depth is an upper bound, and repeated splits do not create a multi-predictor interaction.)
  5. A stump is fitted to the supplied feature \(W=U\times V\). Is it valid to conclude that the stump uses information from only one original predictor? (Answer: No; it splits on one supplied feature, but \(W\) was constructed from the two original predictors.)
Clinical Biostats