Learning outcomes

After this lesson, you will be able to:

The problem

How can we understand why a model returned a particular prediction, and should we trust that explanation?

1. Why a tree looks understandable — and when it really is

Imagine a system that assigns inspection priority to an industrial pump. Instead of returning only “high risk,” it asks a sequence of questions: is vibration above a threshold? If so, is temperature also high? Eventually, the route reaches a leaf with a decision. This path is easier to trace than hundreds of neural-network parameters.

A decision tree is often described as interpretable by design: the model's own structure exposes its prediction logic. For an individual case, we can list the conditions that led to the result. Yet a readable diagram does not guarantee that the tree was well trained, fair, or stable.

Keep three questions separate. Can we read the rule? How accurately does the tree capture patterns in the data? Is it justified to use that rule in a real process? These questions require separate checks. A tree with 25 levels may be technically readable but practically incomprehensible; a short tree may be clear but wrong for important groups.

Scope. This lesson covers trees as models: their structure, decision paths, split criteria, and limitations. Explaining arbitrary black boxes, causal analysis, and fairness audits are separate topics.

2. The parts of a decision tree

A tree consists of nodes connected by branches. The root node contains the first test. An internal node checks a feature and sends an observation down one branch. A leaf asks no further questions and returns a class or a numerical prediction.

Decision treeA model that tests feature-based conditions in sequence and returns a prediction at a terminal leaf.
Root nodeThe starting node containing the first split of the training observations.
Split ruleA test on a feature that routes an observation to one of the child nodes.
Leaf nodeA terminal node with no further tests, storing a class or numerical prediction.

Root node — the starting node containing the first split of the training data.

Split rule — a test such as “vibration is greater than 4.0 mm/s.” For a numerical feature, the algorithm selects a threshold; for a categorical feature, it may test a set of categories, depending on the implementation.

Branch — the route corresponding to the outcome of a test: true or false. A binary tree usually has two branches per split.

Leaf node — a terminal node containing the prediction. In classification, it stores a predicted class and often class proportions; in regression, it stores a number, commonly the mean target value of training observations in that leaf.

3. How a tree makes a decision: a worked example

Suppose the task is to prioritize industrial pump inspections. We use two features: vibration in mm/s and casing temperature in °C. A teaching tree might first test vibration > 4.0. If true, it tests temperature > 70. If both conditions are true, the leaf returns “priority inspection.” If vibration is at or below 4.0, the tree may test something else, such as the number of emergency shutdowns.

Consider a pump with vibration of 5.2 mm/s and temperature of 76 °C. Step 1: 5.2 > 4.0 is true, so we follow the right branch. Step 2: 76 > 70 is true, so we follow the “yes” branch again. Step 3: we reach the “priority inspection” leaf. This is a local explanation: the list of conditions along the route from root to leaf.

For a different pump with vibration of 3.1 mm/s, the first condition is false. A temperature of 76 °C will not change the route if temperature is not tested on that branch. This matters: the model uses only the features and conditions that actually appear along the path. Do not attribute an individual prediction to a feature that was not used on that route.

The diagram is an educational example, not an engineering or regulatory recommendation. The thresholds 4.0 and 70 are chosen to explain the mechanics; they are not universal safety limits.

An observation's path through a decision treeTwo successive tests route an observation from the root node to a prediction leaf.An observation's path through a decision treeRoot: vibration > 4.0?First testNo → another routetemperature not tested hereYes: temperature > 70?Second testNo → routine inspectionYes → priorityNoYesNoYes
A local explanation is the traceable path of tests that one observation follows from root to leaf.

4. How a tree chooses a split

During training, the algorithm searches for a condition that separates observations so that target values in the child nodes become more homogeneous. In classification, homogeneity can be measured with the Gini impurity or entropy. In regression, a common criterion is the reduction in mean squared error or variance.

ImpurityA measure of how mixed the target classes are within a node; it is zero when all observations belong to one class.

A mixture of classes produces a higher value.

For class proportions pₖ, the Gini index is one minus the sum of squared proportions. With two equally represented classes, 0.5 and 0.5, Gini is 0.5; with proportions 1 and 0, it is zero. Entropy measures uncertainty and is also zero for a pure node.

Information gain is the reduction in impurity after a split. The algorithm starts with the parent's impurity and subtracts the weighted impurity of the child nodes. The weights depend on how many observations enter each child. A useful split separates classes without creating unjustifiably tiny groups.

Imagine eight teaching observations: four are labelled “priority” and four “routine.” The parent's Gini is 0.5. A vibration split produces a left child with one priority and three routine cases, and a right child with three priority and one routine cases. Each child has Gini 0.375, so the weighted Gini is 0.375 and the gain is 0.125. This is a small illustrative calculation, not the output of a real training run.

The algorithm evaluates candidate tests and selects one that scores well under the chosen criterion. Similar scores can lead to different trees. Data order, implementation constraints, and randomness can also affect the result.

Gini impurityG = 1 − Σ pₖ²G is node impurity; pₖ is the proportion of class k; k is the number of classes.
EntropyH = −Σ pₖ log₂(pₖ)H is uncertainty in bits; a term with pₖ = 0 is treated as zero.
Information gainIG = I(parent) − Σ (nⱼ / n) · I(childⱼ)I is the selected impurity measure; nⱼ is the child size; n is the parent size.
Node mean squared errorMSE = (1 / n) Σ (yᵢ − ȳ)²yᵢ is the target for observation i; ȳ is the node mean; n is the number of observations.
Path to a leafx → test₁ → branch₁ → … → leafEach test checks a feature; a branch determines the next node; a leaf stores the prediction.

5. Split criteria: what the formulas measure

For class proportions p₁,…,pₖ, the Gini index is 1 − Σpₖ². Here k is the number of classes and pₖ is the proportion of class k in the node. It can be understood as the probability of misclassification under a simple random-labeling thought experiment.

Entropy is −Σpₖ log₂(pₖ). A term with pₖ = 0 is treated as zero by continuity. The base-2 logarithm measures uncertainty in bits.

The weighted impurity after a split is the sum of each child’s impurity multiplied by the fraction of observations sent to that child. Information gain is the parent impurity minus this weighted sum. For regression, a tree may instead use mean squared error: the average squared distance between target values and their mean within a node.

These formulas explain the selection principle; they do not mean that a person must manually test every threshold. The tree implementation performs the search. In practice, inspect the chosen criterion, the model constraints, and the data used for training.

6. Global and local interpretation

A local explanation asks: why did this particular observation reach this leaf? The answer is the complete path of conditions from root to leaf, the leaf prediction, and — for classification — the class proportions or number of training observations supporting it.

A global explanation asks: how does the tree behave overall? Inspect the full structure, depth, number of leaves, features used in splits, distribution of observations across leaves, and performance on independent data. A small tree may be understandable as a diagram; a large tree may require rule summaries and tables.

Tree feature importance often aggregates the reduction in impurity attributed to a feature across all nodes where it is used. This measure depends on the algorithm and the data. It is not a causal effect, does not show the direction of a relationship, and can divide importance across correlated features. Features with many possible thresholds or categories may sometimes have an advantage when candidate splits are evaluated.

A local path and global importance answer different questions. The path shows the tests actually used for one case. Importance aggregates a feature's role across the tree. Do not substitute one for the other.

7. Why an understandable tree can still be wrong

OverfittingA situation in which a tree fits accidental patterns in training data, including noise, and generalizes poorly to new observations.

Tree depth is the maximum number of edges from the root to a leaf. Limits on depth, minimum observations required to split, and minimum observations per leaf help control complexity.

PruningRemoving branches that contribute little to performance on new data in order to control tree complexity.

Pre-pruning limits growth during training; post-pruning first grows a tree and then removes branches according to a complexity and performance criterion.

Trees can be sensitive to the data: a small change in the training sample may change the root split and many downstream branches. With correlated features, the algorithm may choose one of several interchangeable features. A threshold such as 4.0 should not be treated as a natural boundary if nearby values produce similar performance.

Other risks include biased training data, omitted variables, target leakage, changes in the environment after training, and reading class proportions as perfectly calibrated probabilities. Structural interpretability does not repair poor data or prove that a decision is fair.

8. Practice: trace a path and audit stability

Task A — local path. For a pump with vibration 5.2 mm/s and temperature 76 °C, write down every test, its result, the branch taken, and the final leaf. Explain the decision in one sentence without making a causal claim.

Task B — counterexample. Consider a pump with vibration 3.9 mm/s and temperature 82 °C. If the first test is vibration > 4.0, which node is reached? Why might the high temperature not affect this route? What changes when vibration is 4.1 mm/s?

Task C — tree audit. Ask: how deep is the tree; how many observations are in each leaf; how does performance compare on training and test data; are top splits stable across retraining; are features correlated; has the target leaked into the inputs; is performance similar across important groups?

A strong answer traces every condition, explains the threshold and leaf, reports the leaf's size and composition, and separates the model's literal rule from its limitations. If stability or group-level data are unavailable, say so rather than inventing evidence.

9. Summary: an explanation is a path, not a guarantee

A decision tree makes part of its prediction logic explicit: features are tested at nodes, branches define a route, and a leaf returns a result. This makes it possible to explain an individual prediction through a sequence of conditions and inspect the model's overall structure.

But readability is not the same as quality. Check depth, leaf size, split criteria, performance on held-out data, tree stability, and possible bias. Feature importance does not establish causation, and the class proportion in a leaf is not necessarily a well-calibrated probability.

The next module broadens the discussion: we will compare interpretability and accuracy, examine nonlinear models with understandable structure, and move toward GAMs and EBM. The key skill here is to read a rule literally while also checking how much trust it deserves.

Sources and further reading

  1. scikit-learn: Decision Trees — Tree algorithms, classification and regression criteria, and practical limitations.
  2. Molnar: Interpretable Machine Learning — Decision Trees — Interpreting tree structure and local and global explanations.
  3. Breiman et al., Classification and Regression Trees (1984) — A foundational monograph on classification and regression trees.
  4. Quinlan, Induction of Decision Trees (1986) — Foundational work on inductive decision-tree construction.

Lesson glossary

01Decision treeDecision tree

A model that tests conditions in sequence and returns a prediction at a terminal leaf.

02Root nodeRoot node

The starting node containing the first split.

03Split ruleSplit rule

A feature-based test that routes observations to child nodes.

04Internal nodeInternal node

A node that tests a condition and selects a branch.

05Leaf nodeLeaf node

A terminal node containing a class or numerical prediction.

06ImpurityImpurity

A measure of how mixed the target classes are within a node.

07Information gainInformation gain

The reduction in impurity after a split, weighted by child-node sizes.

08PruningPruning

Removing branches to control complexity and reduce overfitting.

09OverfittingOverfitting

Fitting peculiarities of training data at the expense of generalization.

Knowledge check

Choose an answer and select Check answer. Feedback explains the principle.

1. What is a local explanation of a tree prediction?

2. What does a classification leaf return?

3. What does a Gini impurity of zero mean?

4. How is information gain calculated?

5. Why might a feature not affect one prediction?

6. What helps reduce tree overfitting?

7. Does high feature importance prove a causal effect?