Optimal & Interpretable Trees
Why the best tree is NP-hard to find, and modern ways around it.
Greedy growth picks the best split now, not the best tree. Finding the best tree is NP-hard, and a greedy tree can be far from it, yet mixed-integer programming, dynamic programming and branch-and-bound now find provably optimal sparse trees on real datasets. This lesson covers the hardness, the algorithms and their bounds, and the argument that high-stakes decisions should use such models instead of explained black boxes.
What you’ll learn
- State the NP-completeness of optimal decision trees (Hyafil & Rivest, 1976), and explain what it does and does not rule out.
- Construct distributions on which greedy induction is badly myopic, and compute the accuracy it loses at fixed depth.
- Formulate optimal classification trees as a mixed-integer program, and prove the support bounds that let branch-and-bound and dynamic programming certify optimal sparse trees.
- Explain certifiably optimal rule lists, the Rashomon set, and the case for interpretable models in high-stakes decisions.
How hard is the best tree?
Greedy induction optimizes one split at a time. The natural alternative optimizes the whole tree at once, for instance minimizing training error plus a penalty on size over all trees. The first question is how hard that is.
The variants that machine learning cares about, such as deciding whether a labeled sample can be fitted exactly by a tree of a given size or depth, are NP-hard as well. What this does not say is that practical instances are hopeless. NP-hardness is a worst-case statement as the tree size grows with the input. For a fixed depth and binary features, a complete tree chooses one of features at each of its internal nodes, and the best leaf labels follow by majority vote, so brute force over at most trees is polynomial in and , if quickly impractical.
Think first With binary features, a complete depth-2 tree has possible feature assignments. How many does a complete depth-3 tree have?
A depth-3 tree has internal nodes, so there are assignments. Depth 2 is easy by brute force; depth 3 already needs dynamic programming, caching and bounds, which is what the methods below supply.
Greedy myopia
The classic failure is parity. Let be independent fair bits and . A split on either bit leaves both children at 50/50, so every concave impurity shows a decrease of exactly zero, although the depth-2 tree that splits on and then on is perfect. For -bit parity, no split helps until the last level of a depth- tree. A weak distractor turns this zero signal into a real loss at fixed depth:
Add a third bit that equals with probability , independently of everything else. At the root, splits on or leave uniform, while gives children with and :
Greedy splits on . Inside the child , condition on : given , is still a fair coin (because is), and depends on only through , so Bayes' rule gives the same posterior for both values of :
So every second-level split under the root has zero decrease, and the best greedy depth-2 tree predicts , with accuracy 0.6. The depth-2 tree on then is exact.
With the distractor's decrease is , so it captures the root however weak it is, and the depth-2 gap is . Greedy recovers only by growing deeper (depth 3 here), which costs data and readability.
Optimal trees by mixed-integer optimization
Bertsimas & Dunn (2017) wrote the search for an optimal depth- tree as a mixed-integer optimization (MIO) problem. Fix the complete tree of depth , with branch nodes and leaves . For each branch node , binary variables (does it split?) and (on feature ?) and a threshold ; for each example and leaf , a binary (does land in ?); for each leaf, binary class labels and a count of misclassified examples. Features are scaled to , and is smaller than any gap between distinct feature values.
A general MIO solver, warm-started with a CART tree, returns a tree together with a bound on how far it can be from optimal, and proves optimality when the bound closes. Letting range over instead of indicator vectors gives optimal trees with oblique (hyperplane) splits. On 53 UCI datasets, Bertsimas & Dunn reported average out-of-sample gains over CART of 1–2 percentage points with axis-aligned splits and 3–5 with hyperplane splits; the size of the gain varies across datasets and studies. The weakness of generic MIO is scale: the number of binary variables grows with , and solvers often stop at a time limit with a gap still open.
Branch-and-bound and dynamic programming for sparse trees
A second line of work, by Rudin, Seltzer and colleagues, uses binary features (numeric ones are binarized at chosen thresholds), a regularized objective, and specialized search with strong bounds. For a tree with leaves, minimize
Let leaves be siblings with parent , and let be the fraction of all examples that classifies correctly ( for made into a leaf). Merging and saves and loses of accuracy, so optimality requires
The merged leaf predicts the majority label of the union, which does at least as well as predicting 's label on all of it:
Combining the two, , and symmetrically .
A leaf whose sibling is a whole subtree obeys the same bound. Delete and let take the parent's place, so that 's examples are classified by 's leaves. This saves , leaves 's own examples untouched and loses at most , so optimality again forces . Every internal node has leaves below both children, so it is reached by at least of the examples; and since the leaves' correct fractions sum to at most 1, there are at most leaves.
With and training examples, at least how many examples must each leaf of an optimal tree classify correctly?
Show the answer
100 examples
. Each internal node must be reached by at least examples, and an optimal tree has at most leaves. Any partial tree that violates these bounds can be discarded without exploring it.
Such bounds, plus a lower bound for every partial tree (the errors already committed by its finished leaves plus per leaf), let a search discard every partial tree whose bound exceeds the best objective found so far. OSDT (Hu, Rudin & Seltzer, 2019) organized this as branch-and-bound. GOSDT (Lin, Zhong, Hu, Rudin & Seltzer, 2020) recast it as dynamic programming over subproblems, the subsets of examples that can reach a node, stored as bit vectors and cached, and extended it to objectives such as balanced accuracy and F-score. DL8 (Nijssen & Fromont, 2007) and MurTree (Demirović et al., 2022) use dynamic programming over itemsets with caching, MurTree with a specialized solver for depth-2 subtrees. As of the mid-2020s these methods certify optimal shallow trees on many real datasets with thousands of examples; depth and the binarization of continuous features remain the main limits.
Rule lists, the Rashomon set and interpretability
A rule list is a one-sided tree: "if then , else if then , …, else ", each a conjunction of binary features. CORELS (Angelino, Larus-Stone, Alabi, Seltzer & Rudin, 2018) minimizes misclassification plus times the list length by branch-and-bound over prefixes of the list, with a prefix tree, a symmetry-aware map that merges equivalent prefixes, and support bounds like those above, and returns a certificate of optimality.
if (age = 18-20) and (sex = male) then predict yes
else if (age = 21-23) and (priors = 2-3) then predict yes
else if (priors > 3) then predict yes
else predict noA rule list found by CORELS for predicting two-year recidivism on ProPublica's Broward County data. Angelino et al. (2018) report that such optimal sparse rule lists are about as accurate as the proprietary COMPAS risk tool, while every prediction can be checked by hand.
Rudin (2019) drew the policy conclusion. A post-hoc explanation of a black box is a second model that approximates the first, so it can be unfaithful exactly where it matters, and for high-stakes decisions on structured data with meaningful features she argues that interpretable models often match black-box accuracy and should be used instead.
Why would a simple model be nearly as accurate? Consider the Rashomon set: all models in a class whose loss is within of the best (the name is Breiman's, after the film in which witnesses give different but equally plausible accounts). Semenova, Rudin & Parr (2022) argue that when this set is large relative to the hypothesis space, as measured by their Rashomon ratio, it is likely to contain simple models too; a practical sign is that very different methods reach similar accuracy on the same data. Xin et al. (2022) enumerated the entire Rashomon set of sparse decision trees on real datasets, so that users can choose among near-optimal trees by criteria the training objective did not encode, and can study variable importance across the whole set rather than for one tree.
On a tabular dataset, a boosted ensemble, a random forest and a sparse depth-4 tree all reach about the same test accuracy. What does the Rashomon-set view suggest?
- The sparse tree must be overfitting, since it matches far larger models
- The near-optimal set is probably large, so a simple, readable model may lose little accuracy, and conclusions drawn from any single model's structure are fragile
- The ensemble is underfitting and should be grown larger
- The three models must make the same prediction on every example
Show the answer
B. The near-optimal set is probably large, so a simple, readable model may lose little accuracy, and conclusions drawn from any single model's structure are fragile
Similar accuracy from very different model families is the practical signature of a large Rashomon set. It means interpretable models are worth looking for, and also that "the" model is a choice: many models fit equally well while relying on different features.
Key takeaways
- Building trees of minimum expected test count is NP-complete (Hyafil & Rivest, 1976), a worst-case statement as size grows; fixed-depth search is polynomial, if large ( assignments).
- Greedy induction is myopic: parity gives every first split zero decrease, and a weak distractor that agrees with with probability captures the root and costs in accuracy at depth 2.
- Optimal depth- trees can be written as mixed-integer programs with big-M routing constraints (Bertsimas & Dunn, 2017), including oblique splits; generic solvers struggle with scale.
- For , every leaf of an optimal tree classifies correctly at least a fraction of the data and every internal node is reached by at least ; such bounds power branch-and-bound and dynamic programming (OSDT, GOSDT, DL8, MurTree) and CORELS for rule lists.
- Large Rashomon sets explain why simple models are often nearly as accurate as complex ones; Rudin argues that in high-stakes settings they should replace explained black boxes.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What does the NP-completeness result of Hyafil & Rivest (1976) imply?
- No algorithm can find an optimal depth-3 tree on a real dataset
- Greedy trees are always within a constant factor of optimal
- Unless P = NP, no polynomial-time algorithm builds trees of minimum expected test count for every instance as the instances grow
- Decision trees cannot be learned from data efficiently in practice
Show the answer
C. Unless P = NP, no polynomial-time algorithm builds trees of minimum expected test count for every instance as the instances grow
NP-completeness is a worst-case statement about a family of instances of growing size. It is compatible with exact solutions for fixed depth (polynomial, if large) and with specialized solvers that certify optimal shallow trees on real data.
Let for fair bits, and let equal with probability for some small . What does greedy Gini induction do at depth 2?
- Splits on , then , and classifies perfectly
- Splits on first, and its depth-2 accuracy is only
- Picks the root at random, since all three splits tie
- Splits on first, then on , and classifies perfectly
Show the answer
B. Splits on first, and its depth-2 accuracy is only
is the only root split with a positive Gini decrease (). Under it, and remain uninformative one at a time, so no second-level split helps and the tree predicts . The optimal depth-2 tree is exact.
With objective and , at most how many leaves can an optimal tree have?
- 25
- 50
- 100
- There is no bound
Show the answer
B. 50
Each leaf of an optimal tree classifies correctly at least a fraction of the data, and these fractions sum to at most 1, so .
What is Rudin's (2019) main objection to explaining black-box models in high-stakes decisions?
- Explanations are too slow to compute
- Black boxes are always less accurate than interpretable models
- Interpretable models cannot be trained on tabular data
- A post-hoc explanation is a second, approximate model that can be unfaithful to the first, so interpretable models should be used where they perform comparably
Show the answer
D. A post-hoc explanation is a second, approximate model that can be unfaithful to the first, so interpretable models should be used where they perform comparably
An explanation that is right most of the time can still be wrong on the very cases that matter. Rudin argues that on structured data with meaningful features, interpretable models often match black-box accuracy, so the black box and its explanation are unnecessary there.
Further reading
- L. Hyafil & R. L. Rivest, "Constructing optimal binary decision trees is NP-complete," Information Processing Letters 5(1), 15–17 (1976).
- D. Bertsimas & J. Dunn, "Optimal classification trees," Machine Learning 106(7), 1039–1082 (2017).
- X. Hu, C. Rudin & M. Seltzer, "Optimal sparse decision trees," Advances in Neural Information Processing Systems 32 (2019).
- E. Angelino, N. Larus-Stone, D. Alabi, M. Seltzer & C. Rudin, "Learning certifiably optimal rule lists for categorical data," Journal of Machine Learning Research 18(234), 1–78 (2018).
- C. Rudin, "Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead," Nature Machine Intelligence 1(5), 206–215 (2019).