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 training rows and considers every candidate question of the form "is feature below threshold ?". 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,
where is the fraction of the group belonging to class . 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.
Worked example 1: which question wins?
Ten trading days, five up and five down. The parent impurity is
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 and . Weighting by size:
so the impurity drop, the information gain, is .
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 , so the weighted impurity is and the gain is only .
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 (in basis points) have mean and total squared error
Split them into and . The first group has mean and error ; the second has mean and error . Total error is , a reduction of out of . The tree's prediction is now a step function: for anything landing in the left leaf, 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.
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 — fit plus a fee per leaf, with 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)