1. Definition
A Decision Tree is a supervised machine learning algorithm used for classification and regression.
It makes decisions by asking a series of questions or conditions and following the corresponding branches until it reaches a final answer.
In simple words: A Decision Tree works like a flowchart where each question leads to another question or finally to a decision.
2. Simple Example
Suppose we want to predict whether a student will Pass or Fail.
Study > 4 hours?
/ \
Yes No
/ \
Attendance > 75%? FAIL
/ \
Yes No
/ \
PASS FAIL
The tree asks questions one by one and finally gives the prediction.
3. Structure of a Decision Tree
A Decision Tree has four important components.
1. Root Node
The root is the first and topmost decision.
Example:
Study Hours > 4?
It is the starting point of the tree.
2. Decision/Internal Node
An internal node represents a condition or question.
Example:
Attendance > 75%?
3. Branch
A branch represents the outcome of a decision.
For example:
Attendance > 75%?
/ \
Yes No
4. Leaf Node
A leaf node represents the final prediction or result.
Example:
PASS
FAIL
Complete structure
ROOT
│
Decision
/ \
Yes No
/ \
Decision LEAF
/ \ (Fail)
Yes No
/ \
LEAF LEAF
(Pass) (Fail)
4. How Decision Tree Works
The basic process is:
Training Data
↓
Select Best Feature
↓
Create Decision
↓
Split Data
↓
Create More Decisions
↓
Reach Leaf Node
↓
Make Prediction
The algorithm keeps splitting the data until it reaches suitable final groups.
5. Example: Loan Approval
Suppose a bank wants to decide whether to approve a loan.
It may use:
- Income
- Credit score
- Employment status
- Existing loans
A decision tree could look like:
Credit Score > 700?
/ \
Yes No
/ \
Income > ₹50K? Loan Rejected
/ \
Yes No
/ \
Loan Approved Rejected
The tree makes a decision by following the appropriate branch.
6. How Does a Decision Tree Select the Best Feature?
This is an important theoretical question.
A Decision Tree needs to decide:
Which feature should be used for the next split?
Common measures are:
1. Entropy
Entropy measures the impurity or disorder in the data.
The formula is:\[ Entropy(S)=-\sum_{i=1}^{n}p_i\log_2(p_i) \]
Where:
- \(p_i\) = probability of class \(i\)
- \(S\) = dataset
Simple meaning
- Low entropy → data is more pure.
- High entropy → data is more mixed.
7. Information Gain
Information Gain measures how much a particular feature improves the separation of classes.
Formula:\[ IG = Entropy(parent)-Weighted\ Entropy(children) \]
The feature with higher Information Gain is generally preferred for the split.
Simple idea
Before Split
Mixed Data
↓
Apply Feature
↓
After Split
More Pure Groups
Greater reduction in impurity means a better split.
8. Gini Impurity
Another common method is Gini Impurity.
Formula:\[ Gini=1-\sum_{i=1}^{n}p_i^2 \]
The best split generally has lower Gini impurity.
For example:
Gini = 0
↓
Pure group
↓
All observations belong to one class
9. Classification and Regression Trees
Decision Trees can be used for both classification and regression.
Classification Tree
Predicts a category.
Example:
Email → Spam / Not Spam
Regression Tree
Predicts a numerical value.
Example:
House Features → House Price
So:
Decision Tree can solve both classification and regression problems.
10. Advantages of Decision Trees
- Easy to understand and interpret.
- Easy to visualize.
- Can handle classification and regression.
- Does not require complex mathematical calculations during prediction.
- Can handle numerical and categorical features.
- Usually does not require feature scaling.
- Useful for explaining why a particular prediction was made.
11. Disadvantages
1. Overfitting
A Decision Tree can become too large and learn the training data too closely.
Small tree → General pattern
Very large tree → Memorizes training data
This is called overfitting.
2. Can become unstable
Small changes in training data can sometimes produce a very different tree.
3. Large trees become difficult to understand
A very deep tree may contain hundreds of branches.
4. May not perform well on complex relationships
Other algorithms may perform better for some complex datasets.
12. Pruning
Pruning means removing unnecessary branches from a Decision Tree.
It helps to:
- Reduce complexity
- Reduce overfitting
- Improve generalization
- Make the tree easier to understand
Large Tree
↓
Remove unnecessary branches
↓
Smaller Tree
↓
Better Generalization
13. Applications
Decision Trees are used in:
- Loan approval
- Medical diagnosis
- Customer segmentation
- Fraud detection
- Email classification
- Student performance prediction
- Customer churn prediction
- Marketing campaign decisions
- Product recommendation
Digital Marketing Example
A company can use a Decision Tree to predict whether a lead will convert:
Website Visit?
/ \
Yes No
/ \
Viewed Pricing? Low Chance
/ \
Yes No
/ \
High Chance Medium Chance
14. Decision Tree vs KNN
| Decision Tree | KNN |
|---|---|
| Supervised learning | Supervised learning |
| Uses tree structure | Uses nearest neighbours |
| Makes decisions using conditions | Makes decisions using distances |
| Easy to visualize | Simple but less visual |
| Can overfit if very deep | Sensitive to K value |
| Feature scaling usually not required | Feature scaling is important |
| Can do classification and regression | Can do classification and regression |
15. Decision Tree vs Random Forest
This is also important because Random Forest is the next topic in your syllabus.
| Decision Tree | Random Forest |
|---|---|
| Uses one tree | Uses many trees |
| More prone to overfitting | Usually less prone to overfitting |
| Simple to understand | More complex |
| Faster and simpler | More computationally expensive |
| One model | Ensemble of multiple trees |
Easy memory:
Decision Tree = One Tree
Random Forest = Many Decision Trees
16. Exam-Ready Answer
Decision Tree is a supervised machine learning algorithm used for both classification and regression. It represents decisions in the form of a tree structure. The topmost node is called the root node, internal nodes represent decisions or conditions, branches represent the outcomes of decisions, and leaf nodes represent the final predictions. The algorithm selects suitable features for splitting the data using measures such as Information Gain, Entropy and Gini Impurity. Decision Trees are easy to understand and visualize but can suffer from overfitting when the tree becomes very deep. Pruning can be used to reduce overfitting.
Remember:
Decision Tree = Question → Branch → Question → Branch → Final Decision
And for your syllabus, remember that Decision Tree is a supervised learning algorithm, not a clustering algorithm, even if your syllabus groups it under “Clustering.”
