- Introduced by
- Breiman, Friedman, Olshen & Stone
- Year
- 1984
- Type
- Recursive partitioning (if-then rules)
What does it do?
A decision tree is an interpretable method for classification and regression, formalised by Breiman, Friedman, Olshen and Stone in their 1984 CART framework.
It partitions the data with hierarchical if-then rules, and each split sends an observation down one branch or another until a prediction is read off a leaf.
The intuition behind the method
Think of a decision tree as a flowchart of yes/no questions. Starting from all the data, the tree asks at each node the single question about one feature that best separates the cases, for example 'is age above 40?', and divides the data into two groups. Each group is split again in the same way until the cases inside are reasonably homogeneous. The final groups, the leaves, give the prediction, and the chain of questions from root to leaf is a rule any reader can follow.
History
Leo Breiman, Jerome Friedman, Richard Olshen and Charles Stone set out the CART approach in their 1984 monograph Classification and Regression Trees, which treats trees both as a data-analysis method and in terms of their mathematical properties. The transparent if-then structure made trees a staple of applied analysis. Later work combined many trees into ensembles, bagged into Random Forests and boosted in Gradient Boosting, where the instability of any single tree is averaged out.
When to use it
Choose a decision tree when you need a model whose decision rules can be read and communicated, for classification, prediction or exploratory explanation of cross-sectional tabular data. It suits datasets that mix continuous, categorical, binary and ordinal features, since no feature scaling is needed, although categorical inputs may need numeric encoding in the software used. It is a poor choice when the sample is small. As a rough rule of thumb, with about 30 observations or fewer the tree readily overfits, and leaves may hold a single case; the real risk depends on the number of features, the depth allowed and the level of noise. In such cases a simpler, more stable model such as logistic regression or naive Bayes is safer. If predictive stability matters more than one readable structure, a single tree may be the wrong tool and an ensemble such as Random Forest may be more suitable.
Limitations and considerations
- Without limits on depth or leaf size the tree overfits, so pruning controls such as max_depth and min_samples_leaf are an integral part of using the method.
- On small samples leaves may hold very few cases, and the structure becomes unreliable. As a rough rule of thumb, about 30 observations or fewer is a poor basis for a single tree, but the actual threshold depends on the number of features, the depth allowed and the noise level.
- After pruning, a small-sample tree may keep too few splits to be useful, and logistic regression is then more stable.
- A single tree is unstable: small changes in the data can produce a noticeably different set of splits.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The path from root to leaf is a plain if-then rule that can be checked by hand.
- Splits only group or order a feature's values, so no scaling is needed; the CART algorithm handles continuous, categorical, binary and ordinal inputs together, although many libraries require categorical inputs to be encoded as numbers first.
- The structure is simple to present to non-specialists, which makes the tree a common first model to fit.
- Individual trees serve as the building blocks of ensembles such as Random Forest and Gradient Boosting.
Applications
- Interpretable classification of cross-sectional tabular data.
- Prediction and risk segmentation where transparent rules are valued.
- Explanatory analysis to surface which features and thresholds drive an outcome.
- A base learner inside ensembles such as Random Forest and Gradient Boosting.
How it works
How it works
At each node the CART procedure searches over features and candidate thresholds for the split that gives the largest decrease in impurity (the quantity Δi in the mechanics formula, which compares the parent node's impurity with the weighted impurities of its two children). For classification, impurity is measured with the Gini index, i(t) = 1 - sum_k p_k^2, where p_k is the share of class k among the cases at node t. For regression trees, the split is chosen to reduce the within-node sum of squared errors, so that the cases in each child lie as close as possible to their own mean. The chosen split leaves each branch containing cases that are more alike than those in the parent node.
Formula
\Delta i = i(t) - p_L\, i(t_L) - p_R\, i(t_R)
The chosen split is applied and the same search is repeated on each resulting branch, so the data are partitioned again and again. Each split only groups or orders the values of one feature, so no feature scaling is needed, and the CART algorithm itself can split on continuous, categorical, binary and ordinal features. Many software implementations, however, require categorical features to be encoded as numbers first, so the library's documentation should be checked before fitting. When a leaf is reached, its prediction is the majority class of the cases it contains, with the class proportions available as probabilities; for regression, the prediction is the mean response of the cases in the leaf. Without a stopping rule the tree keeps growing until its leaves are almost pure, and this is where overfitting arises.
Growth is restrained to control overfitting. CART's own approach is cost-complexity pruning: a large tree is grown first, then subtrees are removed so as to balance the error of the tree against its size, and the penalty that sets this balance is chosen by cross-validation. Software implementations often offer simpler controls instead, such as limiting depth (max_depth), requiring a minimum number of cases in each leaf (min_samples_leaf), or pruning back branches that add little. The resulting path from root to leaf is a short, transparent decision rule, which is why the model is easy to present to non-specialists.
Common pitfalls
- Growing the tree to full depth without setting max_depth or min_samples_leaf.
- Trusting one deep tree fitted to a small sample, roughly 30 observations or fewer.
- Reading the top split of a fragile tree as a stable explanation of which feature drives the outcome.
- Reporting accuracy on the training data alone, without a held-out test set or cross-validation.
Frequently asked questions
How is a split chosen?
CART evaluates candidate splits across all features and thresholds and picks the one that most reduces node impurity. For classification the impurity is measured with the Gini index.
Why does a decision tree overfit, and how do I stop it?
Left to grow freely a tree keeps splitting until leaves are nearly pure, memorising noise. Restrain it by limiting depth (max_depth), requiring a minimum number of cases per leaf (min_samples_leaf), or pruning back branches that add little. CART's own method, cost-complexity pruning, removes subtrees according to a penalty chosen by cross-validation.
How much data do I need?
There is no fixed minimum. As a rough practical guideline, aim for at least about 30 observations, though the real requirement depends on the number of features, the depth you allow and the noise level. With less data the tree overfits easily, since leaves can contain a single case; a simpler model such as logistic regression or naive Bayes, or cross-validation to judge stability, is then more reliable.
How does a decision tree relate to Random Forest?
A single decision tree is the building block of ensembles: Random Forest grows many trees on resampled data and combines their votes, and Gradient Boosting builds trees sequentially. Both trade the single tree's transparency for greater accuracy and stability.
Related methods
Sources
Breiman, L., Friedman, J.H., Olshen, R.A. & Stone, C.J. (1984). Classification and Regression Trees. Wadsworth.
Open DOI reference08-Classification (Classification: Basic Concepts), Section 8.2 Decision Tree Induction, p. 7