CART, short for classification and regression trees, is a machine learning algorithm that builds a binary decision tree by repeatedly splitting the data on the single feature and threshold that best reduces impurity, then prunes the tree to balance accuracy against complexity. It was formalized in 1984 by Leo Breiman, Jerome Friedman, Richard Olshen and Charles Stone and remains the basis of most modern tree implementations.
The same framework handles classification, where leaves predict a class, and regression, where leaves predict a numeric value. CART trees are the building blocks of random forests and gradient boosting, so understanding the algorithm explains much of how today’s most successful methods for tabular data behave.
How CART grows a tree by recursive partitioning
CART grows a tree through greedy recursive binary partitioning. At each node it evaluates every feature and every candidate threshold, computes how much the split would reduce impurity, and selects the single best split. Each split always produces exactly two child nodes, unlike ID3 or C4.5, which can create one branch per category.
For a numeric feature, candidate thresholds are the midpoints between sorted unique values. For a categorical feature with K levels in a regression or binary task, sorting categories by their mean response finds the optimal grouping in linear time rather than testing all 2 to the power of K partitions. The process repeats on each child until a stopping rule applies, such as a minimum node size.
The table below lists the split criteria that CART uses for each task type.
| Task | Criterion | What it measures | Leaf prediction |
|---|---|---|---|
| Classification | Gini impurity | Probability of misclassifying a random sample | Majority class |
| Classification | Entropy (alternative) | Information content of the class mix | Majority class |
| Regression | Mean squared error | Variance of the target in the node | Mean of the target |
| Robust regression | Mean absolute error | Absolute deviation from the median | Median of the target |
Cost-complexity pruning
The distinctive contribution of CART is cost-complexity pruning, also called weakest-link pruning. Instead of stopping early, the algorithm first grows a large, overfitted tree and then removes branches that add little predictive value relative to their size.
Pruning minimizes the cost function R(T) + α · |T|, where R(T) is the training error, |T| is the number of leaves and α is the complexity parameter. Increasing α produces a nested sequence of smaller subtrees. The final α is chosen by cross-validation, often with the one-standard-error rule, which picks the simplest tree whose error is within one standard error of the minimum.
The following table summarizes the parameters that control tree size in common implementations.
| Parameter | Typical setting | Effect of increasing it |
|---|---|---|
| max_depth | 3 to 12 | Deeper tree, higher variance |
| min_samples_leaf | 1 to 50 | Smoother predictions, lower variance |
| min_samples_split | 2 to 100 | Fewer splits, simpler tree |
| ccp_alpha | Chosen by cross-validation | Stronger pruning, smaller tree |
| max_features | All features in a single tree | Fewer candidates, more randomness |
CART compared with other tree algorithms
CART differs from ID3 and C4.5 mainly in its strictly binary splits, its support for regression and its pruning strategy. The differences matter when reading older literature or choosing software, because the term decision tree is often used for all three.
| Property | CART | ID3 | C4.5 |
|---|---|---|---|
| Split type | Binary only | Multiway | Multiway |
| Criterion | Gini or MSE | Information gain | Gain ratio |
| Regression support | Yes | No | No |
| Numeric features | Thresholds | Not natively | Thresholds |
| Missing values | Surrogate splits | Not handled | Fractional instances |
| Pruning | Cost-complexity | None | Error-based |
Surrogate splits are a further CART feature: for each primary split, the algorithm stores backup splits on other features that mimic it. When a value is missing at prediction time, the best available surrogate routes the sample. Not every library implements surrogates, so missing-value handling varies between packages.
Using CART in practice
A single CART model is most useful when interpretability is a requirement, because the full decision logic can be printed as a set of if-then rules. It needs no feature scaling, handles mixed numeric and categorical data, and captures nonlinear interactions automatically.
| Situation | Recommended approach | Reason |
|---|---|---|
| Rules must be audited by people | Single pruned CART tree | Transparent decision path |
| Maximum accuracy on tabular data | Gradient boosting of CART trees | Lower bias and variance |
| Noisy data, little tuning time | Random forest | Averaging reduces variance |
| Quick exploratory analysis | Shallow tree of depth 3 to 4 | Reveals the strongest drivers |
In scikit-learn, the DecisionTreeClassifier and DecisionTreeRegressor classes implement an optimized version of CART, and R provides the classic implementation through the rpart package with built-in cross-validated pruning.
Limitations and common mistakes
The most serious weakness of CART is high variance: small changes in the training data can produce a completely different tree. Axis-aligned splits also approximate diagonal decision boundaries poorly, needing many steps where a linear model needs one.
- Growing an unpruned tree and reporting training accuracy, which hides severe overfitting.
- Reading impurity-based feature importance as causal, even though it favors features with many distinct values.
- Expecting extrapolation in regression, since predictions never leave the range of training targets.
- Ignoring class imbalance, which lets the majority class dominate Gini reductions.
- Over-interpreting a single tree whose structure may change with a new data sample.
Explained without jargon
CART works like a game of twenty questions. It asks one yes-or-no question about the data, such as whether income is above a set amount. Then it asks a new question in each group. It stops when the groups are clear enough to give an answer.
The answer can be a category, such as approve or decline. It can also be a number, such as a price. At the end, CART trims questions that do not really help. This keeps the tree simple and easy to read.
A typical use case
A regional hospital wants to flag patients at high risk of readmission within 30 days. Clinicians insist on a model they can read and question, so the analytics team trains a CART classifier on about 40,000 past discharges with features such as age, number of prior admissions, length of stay and key laboratory values.
The team grows a full tree, then selects the pruning level with 10-fold cross-validation and the one-standard-error rule. The final tree has eight leaves and a depth of four. Its rules, such as more than two admissions in the past year combined with a long stay, are reviewed by physicians and built into the discharge checklist. A gradient boosting model is slightly more accurate, but the transparent tree wins clinical acceptance and targets follow-up calls at the riskiest patients.