
A Decision Tree is a machine learning algorithm that makes decisions by asking a series of simple questions. These questions are arranged in a tree-like structure, where each internal node represents a decision rule, each branch represents an outcome, and each leaf node represents the final prediction.
In simple words, a decision tree keeps splitting data into smaller groups until it can make a prediction.
It is one of the most practical and easy-to-understand methods in supervised learning, especially for classification and regression tasks.
A decision tree learns from training data by finding the best rule to split the data step by step.
The basic process looks like this:
This repeated splitting is what builds the “tree.”
Before building a decision tree, we first inspect the dataset.
In a simple example, the dataset may have:
The model looks at these features and tries to learn which rules separate the classes best.
For example:
This is how the model starts understanding patterns in the data.
.png)
A decision tree needs to know whether a group of data is “mixed” or “pure.”
A node is called pure when all records in that node belong to the same class.
For example:
One common way to measure this is Gini Impurity.
So the goal of the decision tree is to create splits that reduce impurity as much as possible.
.png)
Once impurity is measured, the model tries different possible rules.
For example:
Each rule splits the parent group into two child groups.
The model then checks how much impurity is reduced after the split. This improvement is called information gain.
In simple words:
The best split is the one with the highest information gain
.png)
A decision tree does not choose a split randomly.
It checks multiple possible decision rules and compares them.
For example, if the model finds:
Then the model will choose:
because it gives higher information gain.
This becomes the rule at the current node.
.png)
After the best split is chosen, the data is divided into child nodes.
Then the same process is repeated again for each child node.
This is called recursive binary splitting.
The model keeps asking:
The splitting usually stops when:
This recursive process is what grows the tree deeper.
.png)
The final nodes of a decision tree are called leaf nodes.
A leaf node does not split further. It gives the final output.
For classification, the leaf node predicts the class.
For example:
Sometimes the leaf can also give prediction probabilities, such as:
So when new data comes in, the model simply moves through the decision rules until it reaches a leaf node.
That is the prediction.
.png)
Even though they are useful, decision trees also have some weaknesses.
Some common limitations are:
Because of this, decision trees are often used as the foundation for stronger models like Random Forest and Gradient Boosted Trees.
Decision trees are used in many real-world applications, such as:
Anywhere a system must make decisions based on a series of conditions, a decision tree can be useful.
Here is a very basic example using scikit-learn:
from sklearn import tree
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(X, y)
prediction = clf.predict([[2., 2.]])
probability = clf.predict_proba([[2., 2.]])This example trains a simple decision tree and then uses it to make a prediction.
Decision trees are one of the best beginner-friendly machine learning algorithms.
They help you understand key ideas like:
These concepts are useful even when you move on to more advanced algorithms.
If you are building your machine learning foundation, decision trees are a great place to start. You may also like What Should You Look for in an Online Machine Learning Course? and Learn Machine Learning Without Quitting Your Job.
A decision tree is a model that learns by asking a sequence of questions.
It starts with the full dataset, finds the best rule, splits the data, and repeats the process until it can make a prediction.
In simple words:
That is what makes decision trees simple, visual, and powerful.
At AI Folks, we help learners understand practical AI and machine learning concepts in a simple way.
Join the AI Folks community to learn AI engineering step by step.
Our community across all our learning platforms spans over 56 countries and over 8000 learners
Weekly updates on AI and Data Sience
Be a part of a vibrant AI community


