MACHINE LEARNING • LESSON 9

How Decision Trees Make Decisions

A Decision Tree makes a prediction by asking questions about the input data, choosing a branch based on each answer, and continuing until it reaches a final result.

THE MAIN IDEA

A Decision Tree makes one decision at a time.

It starts at the top of the tree, checks a condition, follows the matching branch, and repeats this process until it reaches a final prediction.

01

Start With a Question

A Decision Tree starts with a question about the input data.

For our student example, the tree might ask:

FIRST QUESTION Is Study Hours > 3?

The answer can be either Yes or No.

NO 3 hours or less
YES More than 3 hours
02

Follow the Correct Branch

Once the question is answered, the model follows the branch that matches the answer.

Suppose the new student studied for 6 hours.

Study Hours = 6

Is 6 > 3?

Yes

Because the answer is Yes, the tree follows the Yes branch.

QUESTION Study Hours > 3?
↓ YES
RESULT PASS
03

What If the First Question Is Not Enough?

Sometimes one question cannot separate all the data. In that case, the tree can ask another question.

Imagine that the tree first asks:

QUESTION 1 Is Study Hours > 3?

Now suppose we also use attendance.

QUESTION 2 Is Attendance > 80%?

The tree can therefore make a decision in stages.

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

A Complete Example

Let's follow a complete decision from beginning to end.

A student has:

STUDY HOURS 5
ATTENDANCE 90%

The tree asks its first question:

Is Study Hours > 3?

5 > 3

Yes

The tree follows the Yes branch. It now asks the next question.

Is Attendance > 80%?

90 > 80

Yes

The tree reaches the final prediction:

FINAL PREDICTION PASS
05

The Tree Does Not Ask Every Question

An important point is that the model does not necessarily follow every branch in the tree.

It only follows the path that matches the input.

STUDENT A 2 hours

First question → No → Fail

STUDENT B 5 hours + 90% attendance

First question → Yes → Second question → Yes → Pass

Each new input can travel through a different path in the same Decision Tree.
06

How Does the Tree Know Which Question to Ask?

This is where Machine Learning becomes important. We do not normally write every decision by hand.

During training, the Decision Tree examines the training data and looks for splits that separate the classes effectively.

TRAINING DATA Examples
TREE LEARNING Find useful questions
DECISION TREE Questions + Branches

The exact way the tree chooses the best split will be explained later when we study Splitting Data.

07

Decision Tree Prediction in Simple Words

You can think of prediction as walking through the tree.

STEP 1 Start at the top

Begin with the first question.

STEP 2 Answer the question

Check the new input.

STEP 3 Follow the branch

Choose Yes or No.

STEP 4 Reach the prediction

Stop when the tree reaches a final result.

08

Another Real-World Example

Imagine a bank wants to classify a transaction as Normal or Suspicious.

QUESTION 1 Is transaction amount unusually high?
NO Normal
YES
QUESTION 2 Is the location unusual?
NO Normal
YES Suspicious

A transaction does not automatically become suspicious just because it is expensive. The tree can use additional information before making its final decision.

09

Decision Tree vs a Normal If-Else Program

At first, a Decision Tree may look exactly like ordinary if and else code.

For example, we could manually write:

if study_hours > 3:
    prediction = "Pass"
else:
    prediction = "Fail"

This is a normal programming rule.

The important difference is that a Machine Learning Decision Tree can learn useful decision rules from training data instead of requiring us to manually write every rule.

NORMAL PROGRAMMING Human writes the rules

We explicitly tell the program what condition to check and what answer to return.

MACHINE LEARNING Model learns the rules

We provide training examples and the model learns useful decision boundaries.

REMEMBER THIS

A Decision Tree makes a prediction by walking through a series of learned decisions.

Each question sends the input down a different branch. The process continues until the model reaches a final prediction.

New Data Question Branch Question Prediction
QUICK CHECK

Check Your Understanding

How does a Decision Tree start? It starts with a decision or question about the input data.
What happens after a question? The model follows the branch that matches the answer.
Can a tree ask multiple questions? Yes. If one decision is not enough, the tree can continue to another decision.
Does every input follow the same path? No. Different inputs can follow different paths through the same tree.
NEXT TOPIC

Nodes and Branches

Next, we will identify the different parts of a Decision Tree and understand what the root node, decision nodes, branches, and leaf nodes mean.