MACHINE LEARNING • LESSON 9

What Is a Decision Tree?

A Decision Tree is a Machine Learning model that makes predictions by asking a series of simple questions and following different paths to reach an answer.

THE SIMPLEST IDEA

A Decision Tree works like a flowchart of questions.

The model starts with a question, follows the appropriate branch, and continues until it reaches a final prediction.

01

Think of a Decision Tree Like a Flowchart

You have probably used decision-making rules in everyday life without realizing it.

For example, before going outside, you might ask:

QUESTION Is it raining?
YES Take an umbrella
NO No umbrella needed

A Decision Tree works in a similar way. Instead of a person asking the questions, the Machine Learning model learns useful questions from training data.

02

A Simple Machine Learning Example

Let's use the same student example from the previous classification lesson.

We want to predict whether a student will Pass or Fail based on study hours.

STUDY HOURS 1 hour Fail
STUDY HOURS 2 hours Fail
STUDY HOURS 5 hours Pass
STUDY HOURS 7 hours Pass

The Decision Tree can learn a rule that separates these examples.

03

The Tree Can Ask a Question

Based on the training data, the tree might learn a question such as:

DECISION Is Study Hours > 3?

This question divides the students into two groups.

NO 3 hours or less → Fail
YES More than 3 hours → Pass
The important point is that we did not manually write this rule. The Decision Tree learns useful splits from the training data.
04

Following the Tree

Now imagine we have a new student who studied 6 hours.

QUESTION Study Hours > 3?
NO FAIL
YES PASS

For 6 hours:

6 > 3

Yes

Prediction = Pass

The model follows the Yes branch and reaches the Pass prediction.

05

Sometimes a Tree Needs More Than One Question

Real-world data is usually more complicated than our simple study-hours example.

A Decision Tree can therefore ask more than one question.

QUESTION 1 Study Hours > 3?
NO FAIL
QUESTION 2 Attendance > 80%?
YES PASS
NO FAIL

The tree can continue asking questions until it reaches a suitable final decision.

06

What Does the Model Learn?

We give the Decision Tree training examples containing inputs and their correct answers.

X = [
    [1],
    [2],
    [3],
    [5],
    [6],
    [7]
]

y = [
    0,
    0,
    0,
    1,
    1,
    1
]

Here:

X Input

Number of study hours.

y Answer

0 = Fail, 1 = Pass.

The Decision Tree studies these examples and looks for useful ways to separate the different classes.

07

A Real-World Example

Decision Trees are not limited to student predictions. They can be used for many classification problems.

QUESTION Is the transaction amount unusually high?
NO Probably Normal
YES Check More Information

A fraud-detection Decision Tree could continue with additional questions such as the customer's location, transaction history, or device information.

Decision Trees are useful because their decision process can often be easier for humans to understand than a complicated mathematical model.
08

Decision Tree vs Logistic Regression

Both models can be used for classification, but their decision process is different.

LOGISTIC REGRESSION Learns a mathematical relationship

It uses the input features to calculate the probability of each class.

DECISION TREE Learns a sequence of decisions

It asks questions and follows branches until it reaches a prediction.

LOGISTIC REGRESSION Data → Mathematics → Probability → Class
DECISION TREE Data → Question → Branch → Question → Class
09

Why Is It Called a "Tree"?

It is called a tree because the structure starts from one point and branches into different paths.

START Question
PATH 1 Answer
PATH 2 Answer

The structure grows from a starting decision into multiple branches, similar to the branches of a tree.

10

The Basic Decision Tree Process

01 Training Data

Give the model examples.

02 Learn Splits

Find useful questions that separate the data.

03 Build the Tree

Organize the decisions into branches.

04 Make Prediction

Follow the branches for new data.

REMEMBER THIS

A Decision Tree learns questions that divide data into useful groups.

For a new input, the model follows the appropriate branches until it reaches a final prediction.

Training Data Questions Branches Prediction
QUICK CHECK

Check Your Understanding

What is a Decision Tree? A Machine Learning model that makes decisions by following a sequence of questions and branches.
What does the tree learn? It learns useful ways to split the training data into groups.
What happens with new data? The model follows the appropriate branches until it reaches a prediction.
Why is it called a tree? Because one decision can branch into multiple paths, creating a tree-like structure.
NEXT TOPIC

How Decision Trees Make Decisions

Next, we will look at how a Decision Tree chooses questions and follows different paths to make predictions.