Quant Memo
Core

Decision Trees and CART

A model that is literally a flowchart of yes/no questions, grown greedily by always asking whichever question separates the outcomes best. Easy to read, easy to overfit, and the building block of every forest and boosted ensemble.

Prerequisites: The Supervised Learning Framework, Entropy and Information

A linear model insists that the world is a weighted sum: two units more of this feature always moves the answer by the same amount, whatever else is going on. Markets are rarely that polite. Momentum works in quiet regimes and reverses in panics; a wide spread means one thing at the open and another at lunch. What you want is a model that can say "it depends" — and a decision tree is the most literal possible version of that.

The mental picture is a hospital triage flowchart. Is the patient conscious? If no, go left. If yes, is the pulse above 120? And so on, until you reach a box with an instruction in it. A decision tree is exactly this, except the questions are chosen automatically, by looking at data, to make each split as informative as possible. CART — Classification And Regression Trees — is the standard recipe for choosing them.

How a split gets chosen

At the root the algorithm sits on all nn training rows and considers every candidate question of the form "is feature jj below threshold tt?". For each candidate it splits the rows in two and scores the result with an impurity measure: a number that is zero when a group is perfectly uniform and large when it is a mixed bag. For classification the usual choice is the Gini index,

G=1kpk2G = 1 - \sum_{k} p_k^2

where pkp_k is the fraction of the group belonging to class kk. In words: if you drew two rows at random from this group, how often would they disagree? Zero means everyone matches. The split's score is the size-weighted average impurity of the two children, and the winner is whichever question drops it most. Then the algorithm forgets everything else, moves into each child, and repeats. That greed is what makes trees fast and what makes them unstable.

x1 > t1 x2 x1 > t1 ? no yes down x2 > t2 ? flat up
A tree is a set of axis-parallel cuts (left) and the flowchart that produces them (right). Every leaf is one rectangle; every rectangle gets one constant prediction.

Worked example 1: which question wins?

Ten trading days, five up and five down. The parent impurity is

G=1(0.52+0.52)=0.5G = 1 - (0.5^2 + 0.5^2) = 0.5

the maximum possible for two classes — a completely uninformative group. Now score two candidate questions.

Question A: "was the VIX below 20?" Six days answer yes, of which five were up and one down; four answer no, and all four were down. The children's impurities are 1(2536+136)=0.2781 - \left(\tfrac{25}{36} + \tfrac{1}{36}\right) = 0.278 and 1(0+1)=01 - (0 + 1) = 0. Weighting by size:

0.6×0.278+0.4×0=0.1670.6 \times 0.278 + 0.4 \times 0 = 0.167

so the impurity drop, the information gain, is 0.50.167=0.3330.5 - 0.167 = 0.333.

Question B: "was it a Monday?" Five yes days split three up and two down, five no days split two up and three down. Both children score 1(0.62+0.42)=0.481 - (0.6^2 + 0.4^2) = 0.48, so the weighted impurity is 0.480.48 and the gain is only 0.020.02.

CART picks A, cuts the data there, and starts again inside each side. Note it never reconsiders — even if asking B first would have unlocked a better pair of follow-up questions.

Worked example 2: a regression tree

For a numeric target, impurity is just squared error around the group mean. Five days with returns 1,2,3,9,101, 2, 3, 9, 10 (in basis points) have mean 55 and total squared error

16+9+4+16+25=7016 + 9 + 4 + 16 + 25 = 70

Split them into {1,2,3}\{1,2,3\} and {9,10}\{9,10\}. The first group has mean 22 and error 1+0+1=21 + 0 + 1 = 2; the second has mean 9.59.5 and error 0.25+0.25=0.50.25 + 0.25 = 0.5. Total error is 2.52.5, a reduction of 67.567.5 out of 7070. The tree's prediction is now a step function: 22 for anything landing in the left leaf, 9.59.5 for the right. That is all a regression tree ever outputs — a constant per leaf.

A tree carves the feature space into axis-parallel boxes and predicts one constant inside each box. It handles interactions and nonlinearity for free, needs no feature scaling, and cannot extrapolate beyond the range it saw — a leaf's prediction is capped by the training data that fell into it.

Push the flexibility slider below from shallow to deep. The boundary starts as a crude staircase, becomes sensible, then begins fencing off individual points — the classic overfitting arc.

Decision boundary
flexibility 3.0points on wrong side 9reasonable

What this means in practice

Left alone, CART grows until every leaf is pure, which means a training error of zero and a memorised dataset. Two controls stop it: pre-pruning limits (max depth, minimum rows per leaf) and cost-complexity pruning, which grows a big tree and then trims it by minimising R(T)+αTR(T) + \alpha\lvert T\rvert — fit plus a fee per leaf, with α\alpha chosen by cross-validation.

Single trees are seldom deployed on their own. Their value is as the base learner in ensembles: averaging many decorrelated trees kills their variance (Tree Ensembles in Finance, Random Forests and Out-of-Bag Error), while fitting them sequentially to residuals kills their bias (Gradient Boosting in Finance). The readability of one tree plus the accuracy of a thousand is the reason this family dominates tabular finance data.

Trees are high variance: resample the same period and you can get a visibly different tree with similar accuracy, so reading a single tree as an explanation of the market is over-reading it. Relatedly, the impurity-based feature importances printed by default are biased toward high-cardinality and continuous features — a random ID column can look important. Use permutation or out-of-sample importance instead.

Related concepts

Practice in interviews

Further reading

  • Breiman, Friedman, Olshen & Stone, Classification and Regression Trees (1984)
  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (Ch. 9)
  • López de Prado, Advances in Financial Machine Learning (Ch. 6)
ShareTwitterLinkedIn