Tutorials › Exam PA - Predictive Analytics › Choosing Between Shallow And Deep Trees

Exam PA · Single Trees and Rule-Based Prediction · Tutorial 507 of 966

Choosing Between Shallow And Deep Trees

Learn to compare shallow and deep trees by balancing predictive performance against the operational cost of additional leaves and rules.

Intermediate 10 min read

What You'll Learn

  • Distinguish tree depth, number of terminal nodes, and the number of rules users must interpret.
  • Compare classification trees using errors, sensitivity, specificity, and context-specific error costs.
  • Compare regression trees using squared error and root mean squared error.
  • Explain why improved training fit alone does not justify a deeper tree.
  • Make a practical choice when predictive performance and readability point in different directions.

Why Tree Size Is a Predictive Choice

A shallow tree is usually easier to explain: it makes predictions using fewer successive decisions and produces fewer terminal-node rules. A deeper tree can represent more detailed patterns, but that detail is useful only if it improves predictions in a way that matters for the intended decision. The aim is not to select the smallest tree automatically or the deepest tree automatically. It is to compare candidate trees on both predictive performance and practical usability.

This comparison is aligned with the SOA Exam PA (Predictive Analytics) syllabus. The earlier material on cost-complexity pruning explains how candidate tree sizes can be produced; here the question is how to decide whether the additional detail is worthwhile. A fair predictive comparison uses the same observations not used to fit either candidate. Those observations provide evidence about how each tree may perform on new cases.

Definition: A tree's depth is the greatest number of split decisions along any path from the root to a terminal node. A terminal node (or leaf) is a node that makes a prediction rather than splitting again. Each root-to-leaf path can be written as a rule. Depth and leaf count describe different aspects of size: a tree can have paths of unequal lengths, so its depth alone does not determine its number of leaves.

A larger tree can make its training predictions more detailed because it divides the data into smaller groups. In regression, fitting a separate mean to each smaller group cannot increase the minimum training sum of squared errors. In classification, additional splits can likewise change the predicted class in smaller regions. Neither fact guarantees improved prediction for observations outside the training data: small groups may reflect patterns that do not repeat.

Compare Performance on the Same Assessment Data

For a regression tree, a common measure is mean squared error (MSE): the average squared difference between observed and predicted outcomes. Root mean squared error (RMSE), the square root of MSE, is expressed in the outcome's units. For a classification tree, the error rate is the fraction of cases classified incorrectly. These measures summarize different aspects of performance, so the measure should match the prediction task.

An overall error rate can also hide the practical consequences of mistakes. For a binary outcome, a false negative is an actual positive case predicted negative; a false positive is an actual negative case predicted positive. If the two error types have different consequences, compare them separately or use an explicitly specified cost. For example, a hypothetical claim-review process may regard failing to flag a high-cost claim as more serious than sending an unnecessary claim for review.

Key takeaway: Compare candidate trees on the same assessment cases using a measure suited to the decision. Then consider whether any predictive advantage is large and useful enough to justify the extra leaves, rules, and explanation burden.

Worked Example: Classification Accuracy and Additional Leaves

A hypothetical insurer uses a tree to flag accounts for a manual review. On a held-out set of 40 accounts, the actual outcomes and predictions are summarized by tree. The compact tree has two leaves. It predicts “no flag” for a group containing 20 accounts, of which 6 actually require a flag; it predicts “flag” for the other 20 accounts, of which 12 actually require a flag. A deeper tree has four leaves. In its first half, the two leaves contain 10 accounts each, with 1 and 5 actual flags; both leaves predict “no flag.” In its second half, the two leaves contain 10 accounts each, with 9 and 3 actual flags; the first predicts “flag” and the second “no flag.” Compare the held-out error rates and state what the added leaves accomplish.

Method. Count incorrect classifications in each terminal group, add them, and divide by the same total of 40 accounts. This comparison avoids treating a larger number of rules as evidence of better prediction by itself.

For the compact tree, the first leaf predicts “no flag,” so its 6 actual flags are errors. The second predicts “flag,” so its 20 total accounts minus 12 actual flags gives 8 errors. Thus:

$$ \text{errors}_{\text{compact}}=6+8=14,\qquad \text{error rate}_{\text{compact}}=\frac{14}{40}=0.35. $$

For the deeper tree, the first half contributes \(1+5=6\) errors because both leaves predict “no flag.” In the second half, the leaf with 9 actual flags contributes \(10-9=1\) error; the leaf with 3 actual flags predicts “no flag” and contributes 3 errors. Therefore:

$$ \text{errors}_{\text{deep}}=6+1+3=10,\qquad \text{error rate}_{\text{deep}}=\frac{10}{40}=0.25. $$

The deeper tree reduces the held-out error rate by \(0.35-0.25=0.10\), or 10 percentage points, on these 40 cases. It uses two additional leaves to distinguish groups that the compact tree treated alike. That improvement is evidence in favor of the deeper tree, but a final choice should also consider whether a 10-point gain is sufficiently valuable to justify explaining and maintaining four rules rather than two.

Check. The deeper tree has \(40-10=30\) correct classifications, and \(30/40=0.75\); its accuracy is therefore 75%, consistent with a 25% error rate.

What Leaf Predictions Optimize

Understanding how a terminal-node prediction is chosen helps explain why smaller leaves can look better on training data. In a regression tree using squared-error loss, a leaf predicts the mean of the response values in that leaf. In a classification tree using ordinary misclassification error, a leaf predicts the most common class in that leaf. These choices minimize the respective loss within that fixed leaf; they do not establish that the tree's entire set of splits will predict well on new cases.

Justification: For responses \(y_1,\ldots,y_n\) in one fixed regression leaf, the constant prediction \(a\) has sum of squared errors \(Q(a)=\sum_{j=1}^{n}(y_j-a)^2\). Differentiating gives \(Q'(a)=-2\sum_{j=1}^{n}(y_j-a)\). Setting this equal to zero yields \(a=\frac{1}{n}\sum_{j=1}^{n}y_j\). Since \(Q''(a)=2n>0\), this value minimizes the sum of squared errors. In a classification leaf, predicting a given class makes an error for every observation not in that class; the most frequent class therefore minimizes the number of errors in that leaf.

The derivation applies to the prediction within a fixed leaf under squared-error loss. It does not show that adding a split improves performance on new data, nor does it apply unchanged when a different loss or prediction objective is used. The important distinction is between fit within the observed leaves and performance on cases used to assess the candidate tree.

Worked Example: Regression Fit Versus Held-Out Performance

A hypothetical model predicts the repair cost, in thousands of dollars, for a type of equipment. On the training data, the eight observed costs are \(2,4,6,8,10,12,14,16\). A compact tree has two leaves: the first contains the first four values and the second contains the last four. A deeper tree splits each of those groups into pairs. Compare their training RMSEs. Then compare held-out RMSEs when four new cases have actual costs \(5,5,13,13\), with compact-tree predictions \(5,5,13,13\) and deeper-tree predictions \(3,7,11,15\).

Method. Find the mean prediction in each training leaf, calculate squared residuals, and divide the total by the number of observations before taking the square root. Then calculate the same metric from the given held-out predictions. This separates the tree's training fit from its predictive performance on new cases.

For the compact tree, the first leaf mean is \((2+4+6+8)/4=20/4=5\); its squared residuals are \(9,1,1,9\), summing to 20. The second leaf mean is \((10+12+14+16)/4=52/4=13\); its squared residuals are also \(9,1,1,9\), summing to 20. Thus the total training sum of squared errors is \(20+20=40\), and:

$$ \operatorname{RMSE}_{\text{compact, training}} =\sqrt{\frac{40}{8}} =\sqrt{5} \approx 2.236. $$

For the deeper tree, the four pairwise means are \((2+4)/2=3\), \((6+8)/2=7\), \((10+12)/2=11\), and \((14+16)/2=15\). Each pair has residuals \(-1\) and \(1\), so each contributes \(1+1=2\) to the sum of squared errors. The total is \(4(2)=8\), giving:

$$ \operatorname{RMSE}_{\text{deep, training}} =\sqrt{\frac{8}{8}} =1. $$

On the four held-out cases, the compact tree's predictions match the actual values exactly, so its sum of squared errors and RMSE are both 0. The deeper tree's residuals, actual minus predicted, are \(2,-2,2,-2\). Their squared values sum to \(4+4+4+4=16\), so:

$$ \operatorname{RMSE}_{\text{deep, held-out}} =\sqrt{\frac{16}{4}} =2. $$

The compact tree performs better on these held-out cases even though the deeper tree has lower training RMSE. A common mistake would be to select the deeper tree solely because \(1<2.236\) on training data. The correction is to use the held-out comparison for evidence about prediction on new cases, while recognizing that four held-out observations provide limited evidence. The calculations are consistent: each held-out RMSE is in thousands of dollars, and the compact tree has zero error on the specified cases.

When Error Types Have Different Consequences

A deeper tree need not reduce the total number of errors to be preferable. It may shift the balance between error types in a way that better matches the decision. The following comparison uses hypothetical claim-review results. The stated cost units are decision weights, not observed company expenses.

Worked Example: Choosing a Tree Using Error Costs

A hypothetical review team compares two trees on the same 50 held-out claims. There are 10 claims that truly require review and 40 that do not. The compact tree produces 8 true positives, 2 false negatives, 8 false positives, and 32 true negatives. The deeper tree produces 9 true positives, 1 false negative, 12 false positives, and 28 true negatives. The team assigns a cost of 5 units to each false negative and 1 unit to each false positive. Compare accuracy and total weighted error cost.

Method. First calculate errors and accuracy using all 50 claims. Then multiply each error count by its specified cost and add the results. This avoids assuming that an error rate alone captures the team's objective.

The compact tree makes \(2+8=10\) errors, so its accuracy is \((50-10)/50=40/50=0.80\), or 80%. Its weighted error cost is:

$$ 2(5)+8(1)=10+8=18\text{ units}. $$

The deeper tree makes \(1+12=13\) errors, so its accuracy is \((50-13)/50=37/50=0.74\), or 74%. Its weighted error cost is:

$$ 1(5)+12(1)=5+12=17\text{ units}. $$

The compact tree has higher accuracy, but the deeper tree has lower weighted cost by \(18-17=1\) unit because it produces one fewer false negative at the expense of four additional false positives. If the stated costs accurately represent the team's priorities, the deeper tree is favored on this measure despite its lower accuracy. The conclusion is conditional on the specified costs; if ease of explanation or other consequences matter, those should also be considered. The check is direct: the compact tree's 40 correct predictions plus 10 errors, and the deeper tree's 37 correct predictions plus 13 errors, each sum to 50.

A Practical Comparison

A useful comparison is explicit about both the prediction objective and the size being added. Before choosing, establish that the candidates are assessed on the same cases and that the reported measure reflects the intended use. Then ask what the added leaves change: do they reduce important errors, improve the outcome-scale accuracy, or provide detail that a decision-maker can act on? A small numerical improvement may not justify a substantially harder set of rules to communicate or maintain.

1
Describe the candidates.
Record the number of leaves, maximum depth, and the main distinctions in their root-to-leaf rules. Do not treat depth and leaf count as interchangeable.
2
Choose a relevant performance measure.
Use a regression measure such as RMSE for a quantitative response, or classification measures suited to the decision. If errors have different consequences, state how those consequences are represented.
3
Compare on the same assessment cases.
Calculate each candidate's measure using the same observations and the same definitions. A comparison of different samples can mix the effect of tree size with differences in case composition.
4
Assess whether the gain is useful.
Translate a numerical difference into its practical meaning, then weigh it against extra rules, explanation effort, and the needs of the people using the prediction.

Several pitfalls can distort this choice:

  • Choosing from training fit alone. Smaller training error for a deeper tree is not, by itself, evidence of improved prediction on new cases.
  • Comparing unlike summaries. Compare the same metric, with the same units and definition, for both trees. For example, do not compare one tree's RMSE with another's MSE.
  • Using accuracy when error consequences differ. Equal error counts can have very different consequences if one type of mistake is more costly.
  • Equating a longer rule list with useful insight. Extra conditions may make a tree harder to explain without improving the predictions or decisions that matter.
  • Claiming certainty from a small assessment set. A measured advantage on a limited number of cases is evidence, not a guarantee of future performance.
Key takeaway: Prefer additional tree detail only when its predictive benefit on relevant assessment cases is meaningful for the decision and worth the added complexity. If performance is similar, the more compact tree may be easier to communicate; if a deeper tree improves an important outcome enough to justify its rules, its added detail may be worthwhile.

Check Your Understanding

For each question, compare the stated results rather than assuming that a deeper tree is automatically better.

  1. Two classification trees are assessed on the same 25 cases. The compact tree makes 5 errors and the deeper tree makes 4. Calculate each error rate and state which has the lower observed error rate. (Answer: Compact \(5/25=0.20\); deeper \(4/25=0.16\); the deeper tree is lower by 0.04, or 4 percentage points.)
  2. On two held-out regression cases, actual values are 3 and 7. A compact tree predicts 4 and 6; a deeper tree predicts 2 and 8. Calculate both RMSEs and state whether this comparison favors one tree. (Answer: Both have squared errors \(1+1=2\), so each RMSE is \(\sqrt{2/2}=1\); they tie.)
  3. A compact classifier has 2 false negatives and 4 false positives. A deeper classifier has 1 false negative and 7 false positives. If a false negative costs 3 units and a false positive costs 2 units, calculate the total cost for each. (Answer: Compact \(2(3)+4(2)=14\) units; deeper \(1(3)+7(2)=17\) units; the compact tree has lower stated cost by 3 units.)
  4. A regression tree's training RMSE falls from 4.0 to 2.5 when the tree is made deeper, but the assessment RMSE rises from 3.0 to 3.6. Which candidate has the lower assessment error, and why is the training result insufficient to select the deeper tree? (Answer: The compact candidate has lower assessment RMSE, 3.0 versus 3.6; lower training RMSE alone does not establish better prediction on assessment cases.)
Clinical Biostats