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.
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.
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:
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.
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.
The Decision Tree can learn a rule that separates these examples.
The Tree Can Ask a Question
Based on the training data, the tree might learn a question such as:
This question divides the students into two groups.
Following the Tree
Now imagine we have a new student who studied 6 hours.
For 6 hours:
6 > 3
Yes
Prediction = Pass
The model follows the Yes branch and reaches the Pass prediction.
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.
The tree can continue asking questions until it reaches a suitable final decision.
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:
Number of study hours.
0 = Fail, 1 = Pass.
The Decision Tree studies these examples and looks for useful ways to separate the different classes.
A Real-World Example
Decision Trees are not limited to student predictions. They can be used for many classification problems.
A fraud-detection Decision Tree could continue with additional questions such as the customer's location, transaction history, or device information.
Decision Tree vs Logistic Regression
Both models can be used for classification, but their decision process is different.
It uses the input features to calculate the probability of each class.
It asks questions and follows branches until it reaches a prediction.
Why Is It Called a "Tree"?
It is called a tree because the structure starts from one point and branches into different paths.
The structure grows from a starting decision into multiple branches, similar to the branches of a tree.
The Basic Decision Tree Process
Give the model examples.
Find useful questions that separate the data.
Organize the decisions into branches.
Follow the branches for new data.
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.