Machine Learning

Decision Trees: how a model makes decisions step by step

August 20, 2025 12 min read Lorenzo Mascia

Decision Trees are one of the most intuitive models in Machine Learning, because they mirror the way humans often reason about decisions. Instead of learning a single mathematical formula, a Decision Tree breaks a problem down into a sequence of simple questions. Each question narrows the possibilities, step by step, until a final decision is reached. This structure makes Decision Trees uniquely transparent in a field that often struggles with interpretability.

How Decision Trees Work

At a conceptual level, a Decision Tree works by repeatedly splitting the data based on feature values. At each step, the model asks a question like "Is this value greater than a certain threshold?" or "Does this belong to a specific category?" Based on the answer, the data flows down one branch or another. Over time, these splits form a tree-like structure where each path represents a decision rule learned from data.

What makes this approach powerful is that the model is not guessing randomly. Each split is chosen to reduce uncertainty as much as possible. The tree looks for the question that best separates the data into more homogeneous groups, meaning groups that are more similar in terms of the target outcome. In classification, this means purer classes. In regression, it means more consistent numerical values. The tree keeps splitting until it reaches a stopping condition, such as a maximum depth or a minimum number of samples.

The Power of Interpretability

One of the defining strengths of Decision Trees is interpretability. You can follow a single prediction from the root of the tree to a leaf and see exactly which decisions were made and why. This makes trees especially valuable in domains where transparency matters, such as finance, healthcare, or any system where decisions must be explained to humans. Unlike many other models, a Decision Tree does not hide its logic behind abstract parameters.

At the same time, this step-by-step reasoning comes with trade-offs. A single Decision Tree is highly flexible and can model complex, non-linear relationships, but this flexibility makes it prone to overfitting. If allowed to grow without constraints, a tree can memorize the training data, creating very specific rules that fail to generalize to new cases. This behavior reflects a broader Machine Learning principle: interpretability and flexibility often come at the cost of robustness.

Natural Feature Selection

Decision Trees also reshape how you think about features. The model naturally performs feature selection by choosing which variables to split on and when. Features that are informative appear near the top of the tree, influencing many decisions. Less useful features may appear only deep in the tree or not at all. This property makes trees a useful exploratory tool, even when they are not the final model used in production.

To make all of this concrete, let's look at a practical example with Python.

A Practical Example

Imagine you want to decide whether a loan should be approved based on two simple features: income and existing debt. The output is binary: approve or reject. You want a model whose decisions you can explain clearly.

import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

First, let's create a small dataset.

# Features: [income (k€), debt (k€)]
X = np.array([
    [30, 5],
    [35, 12],
    [40, 8],
    [50, 10],
    [60, 5],
    [70, 20],
    [80, 10],
    [90, 5]
])

# Labels: 0 = reject, 1 = approve
y = np.array([0, 0, 0, 1, 1, 0, 1, 1])

Now we split the data into training and test sets.

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, random_state=42
)

Next, we create and train a Decision Tree. We limit its depth to keep it interpretable and reduce overfitting.

model = DecisionTreeClassifier(max_depth=3, random_state=42)
model.fit(X_train, y_train)

Let's evaluate the model.

y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)

print("Accuracy:", accuracy)

Now let's make a prediction for a new applicant with an income of 55k and debt of 7k.

new_applicant = np.array([[55, 7]])
prediction = model.predict(new_applicant)

print("Loan approved:", bool(prediction[0]))

Understanding the Results

Behind this single prediction is a clear chain of decisions. The tree might first ask whether income is above a certain threshold. If yes, it might then ask whether debt is below another threshold. Each answer moves the applicant closer to approval or rejection. You can extract and visualize these rules, making the decision process explicit and inspectable.

This example shows why Decision Trees are such a valuable learning tool. They expose the mechanics of decision-making instead of hiding them. They help you understand how features interact, where models can overfit, and how complexity grows as rules become more specific.

Decision Trees teach an essential lesson in Machine Learning: intelligence does not always come from complex mathematics. Sometimes it comes from structuring decisions clearly and applying them consistently. Even when you later move on to more advanced models like ensembles or boosting, the intuition built by understanding a single Decision Tree remains foundational.