Decision Trees
Intermediate 12 min read Decision Trees

When to Use Decision Trees

The right tool, at the right scale

Use trees when explainability, mixed features, non-linearities and interpretable thresholds matter and the data is small-to-mid; scale or complexity needs demand forests/boosting instead.

when to use treestradeoffsinterpretabilitymixed featuresauditalternatives
Before we start

What you will learn

  • Enumerate when a single tree beats linear/forest/NNs
  • Name the conditions that disqualify a single tree
  • Give the escalation path (forest/boosting) with reasons
Introduction

What is this?

Single decision trees shine where a simple, auditable rule must be stated: regulatory thresholds, triage gates, bootstraps, and small mid-dimensional data. They lose to forests/boosting on raw accuracy and stability, and to specialized models on text/images/IoT sequences. The decision is: 'Do I need a readable flowchart, at acceptable variance, on modest data?'

Motivation

Why do you need it?

  • Nothing else prints a policy you can legally attach to a filing.
  • Mixed dtypes and non-linearities get handled with zero preprocessing.
  • The rule is explainable end-to-end without add-on libraries.
  • When constraints flip (accuracy over audit), the tree passes the baton deliberately.
Think about it

Mental model

Imagine

A printed decision poster vs an app

Think of

Single tree vs forest/NN

The poster (tree) serves when staff need to read the rule offline — one page, no phone, no updates. When volume and accuracy matter more, ship the app (ensemble).

Mechanics

How it works

  • Score the context: who must read the model? Is the rule stable across retrains?
  • Check data size: trees handle small-mid; at scale, forests/boosting dominate speed-of-fix.
  • Prototype a tree; compare against the forest/linear baseline on validation.
  • If a tree loses but audit wins, keep a pruned tree and document the accuracy cost.
  • Escalate to forest/boosting when the accuracy gap matters and interpretation via SHAP suffices.

Tree decision gate.

Audit needs
Data size
Accuracy gap
SHAP
Hands-on

Examples

A decision-realistic comparison

A decision-realistic comparison
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import cross_val_score, StratifiedKFold
X, y = make_classification(n_samples=1500, n_features=20, n_informative=9,
flip_y=0.1, random_state=0)
cv = StratifiedKFold(5)
tree = cross_val_score(DecisionTreeClassifier(max_depth=6, random_state=0), X, y, cv=cv)
bag = cross_val_score(RandomForestClassifier(n_estimators=200, random_state=0), X, y, cv=cv)
print("single tree F1:", round(tree.mean(), 4))
print("forest F1:", round(bag.mean(), 4))
print("=> auditable tree vs higher-accuracy forest: pick by the audit requirement")

The forest typically wins, yet a regulated team may still ship the tree because the flowchart's audit value outweighs the small AU-grade.

Real world

In production

  • Fraud rule engine: a shallow tree of 'block if X and Y' is operationalizeable and reviewable by analysts.
  • Approval routing: tree gates route to teams without calls to big models.
  • Regulated underwriting: a written-scorecard tree is the product.
Guidelines

Best practices

  • Prototype the tree before assuming; measure the accuracy cost of interpretability in the deck; set stability checks (2 seeds) before promoting a single-tree product.
Watch out

Common mistakes

  • Using a single tree where the business needs top accuracy (forest is 2 lines away); claiming 'tree = interpretable' on depth-25 monsters; skipping stability documentation.
When things break

Debugging tips

  • If the tree loses by >0.02 F1, decide explicitly: audit is worth the cost, or SHAP the forest.
  • Rendering latency of deep trees at peak load: prune before serving.
  • Mixed audit usage: keep the export_text alongside the live threshold config.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

The strongest case for a SINGLE tree over a forest is?

2

At large scale with peak-latency serving, a deep single tree's danger is?

Go deeper

Official documentation