CART

Also known as: Classification and regression trees

On this page 7

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.

TaskCriterionWhat it measuresLeaf prediction
ClassificationGini impurityProbability of misclassifying a random sampleMajority class
ClassificationEntropy (alternative)Information content of the class mixMajority class
RegressionMean squared errorVariance of the target in the nodeMean of the target
Robust regressionMean absolute errorAbsolute deviation from the medianMedian of the target
Split criteria in classification and regression trees

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.

ParameterTypical settingEffect of increasing it
max_depth3 to 12Deeper tree, higher variance
min_samples_leaf1 to 50Smoother predictions, lower variance
min_samples_split2 to 100Fewer splits, simpler tree
ccp_alphaChosen by cross-validationStronger pruning, smaller tree
max_featuresAll features in a single treeFewer candidates, more randomness
Parameters that control CART complexity

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.

PropertyCARTID3C4.5
Split typeBinary onlyMultiwayMultiway
CriterionGini or MSEInformation gainGain ratio
Regression supportYesNoNo
Numeric featuresThresholdsNot nativelyThresholds
Missing valuesSurrogate splitsNot handledFractional instances
PruningCost-complexityNoneError-based
CART, ID3 and C4.5 compared

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.

SituationRecommended approachReason
Rules must be audited by peopleSingle pruned CART treeTransparent decision path
Maximum accuracy on tabular dataGradient boosting of CART treesLower bias and variance
Noisy data, little tuning timeRandom forestAveraging reduces variance
Quick exploratory analysisShallow tree of depth 3 to 4Reveals the strongest drivers
Choosing between a single tree and tree ensembles

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.