# Supervised LearningClassification & Prediction (Used in Predictive Analytics)

course: Module 2 — Machine Learning Algorithms
module: Module-2-Machine-Learning-Algorithms
type: pdf
source_url: https://personal-learn.armco.dev/files/Module-2-Machine-Learning-Algorithms/General/Supervised_LearningClassification_&_Prediction_(Used_in_Predictive_Analytics).pdf
pages: 40

---
[page 1]
IIT Roorkee – Futurense
PG Certification 
GenAI and Agentic AI for Engineers
Supervised Learning  
Dr Durga Toshniwal
Professor
Department of Computer Science & Engg.
Indian Institute of Technology Roorkee
durga.toshniwal@cs.iitr.ac.in, durgatoshniwal@gmail.com
www.durgatoshniwal.in

[page 2]
Today’s Agenda
• Classification
• Decision Tree Induction
• Issues and Challenges
• How to decide for Best Split
• Model Overfitting and Underfitting
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 3]
Supervised Learning
Classification & Prediction 
(Used in Predictive Analytics)  
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 4]
Classification – A 2 step process
GenAI and Agentic AI - Prof Durga 
Toshniwal
Given a collection of records (training set )
– Each record is characterized by variables (x,y), 
where x is the attribute set and y is the class 
label
x: attribute, predictor, independent variable, input
y: class, response, dependent variable, output
Task:
– Learn a model that maps each attribute set x 
into one of the predefined class labels y

[page 5]
Classification – A 2 step process
• Model construction
• Model usage
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 6]
Classification – A 2 step process
• Model construction: describing a set of 
predetermined classes
– Each sample belongs to a predefined class, as 
determined by the class label attribute
– The set of samples used for model construction is 
training set
– The model can be represented as decision trees 
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 7]
Classification – A 2 step process
• Model usage: for classifying future or 
unknown objects
– Estimate accuracy of the model
• The known label of test sample is compared with the 
classified result from the model
• Accuracy rate is the percentage of test set samples 
that are correctly classified by the model
• Test set is independent of training set 
– If the accuracy is acceptable, use the model to classify 
data tuples whose class labels are not known
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 8]
Classification by Decision Tree Induction
• It involves the learning of decision trees from 
class labeled training tuples
• It is a flow-chart like tree structure
• Each internal node is a test on an attribute
• Each branch is an outcome of the test
• Each leaf holds a class label
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 9]
Example of a Decision Tree
Tid Refund Marital
Status
Taxable
Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes
10
Refund
MarSt
TaxInc
YESNO
NO
NO
Yes No
Married Single, Divorced
60 - 80K,
100 – 250K 80  - 100K
Splitting Attributes
Training Data Model:  Decision Tree
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 10]
Another Example of Decision Tree
Tid Refund Marital
Status
Taxable
Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes
10
MarSt
Refund
TaxInc
YESNO
NO
NO
Yes No
Married 
Single, 
Divorced
There could be more than one tree that 
fits the same data!
GenAI and Agentic AI - Prof Durga 
Toshniwal
60 - 80K,
100 - 250K 80 - 
100K

[page 11]
Decision Tree Induction
• Many Algorithms:
– Hunt’s Algorithm (Others are based on this)
– CART
– ID3, C4.5
– SLIQ,SPRINT
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 12]
General Structure of Hunt’s 
Algorithm
• Let Dt be the set of training records that 
reach a node t, y = {y1, y2…yn} are class 
labels
• Idea: Partition the training records to 
obtain successively purer subsets
• General Recursive Procedure:
– If Dt contains records that belong to 
the same class yt, then t is a leaf 
node labeled as yt
– If Dt is an empty set, then t is a leaf 
node labeled by the default class, yd
– If Dt contains records that belong to 
more than one class, use an attribute 
test to split the data into smaller 
subsets. Recursively apply the 
procedure to each subset.
Tid Refund Marital 
Status 
Taxable 
Income Cheat 
1 Yes Single 125K No 
2 No Married 100K No 
3 No Single 70K No 
4 Yes Married 120K No 
5 No Divorced 95K Yes 
6 No Married 60K No 
7 Yes Divorced 220K No 
8 No Single 85K Yes 
9 No Married 75K No 
10 No Single 90K Yes 
10 
 
Dt
?
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 13]
Hunt’s Algorithm
Don’t 
Cheat
Refund
Don’t 
Cheat
Don’t 
Cheat
Yes No
Refund
Don’t 
Cheat
Yes No
Marital
Status
Don’t 
Cheat
Cheat
Single,
Divorced Married
Taxable
Income
Don’t 
Cheat
80K – 100K
Refund
Don’t 
Cheat
Yes No
Marital
Status
Don’t 
CheatCheat
Single,
Divorced Married
Tid Refund Marital
Status
Taxable
Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes
10
Refund
Don’t 
Cheat
Yes No
Marital
Status
Don’t 
Cheat
Cheat
Single,
Divorced Married
Taxable
Income
Don’t 
Cheat
GenAI and Agentic AI - Prof Durga 
Toshniwal
60 - 80K,
100 - 250K

[page 14]
Hunt’s Algorithm
Tid Refund Marital 
Status 
Taxable 
Income Cheat 
1 Yes Single 125K No 
2 No Married 100K No 
3 No Single 70K Yes 
4 No Single 70K No 
5 No Divorced 95K Yes 
6 No Married 60K No 
7 Yes Divorced 220K No 
8 No Single 85K Yes 
9 No Married 75K No 
10 No Single 90K Yes 
10 
 
Refund
Don’t 
Cheat
Yes No
Marital
Status
Don’t 
Cheat
Cheat
Single,
Divorced Married
Taxable
Income
Don’t 
Cheat
Refund – Yes , No
Marital Status – Married, Single/ Divorced
Taxable Income – {60 to 80K, 100 to 250K}
                             {80 to 100K}
GenAI and Agentic AI - Prof Durga 
Toshniwal
60 - 80K,
100 - 250K 80K – 100K

[page 15]
Hunt’s Algorithm
Additional Conditions:
– It may be possible that a 
child node is empty . 
– This may be possible if 
none of the training 
records have the 
combination of attribute 
values associated with 
such nodes
– In that case, node is 
declared a leaf node with 
the same class label as 
that associated with its 
parent
Refund
Don’t 
Cheat
Yes No
Marital
Status
Don’t 
Cheat
Cheat
Single,
Divorced Married
Taxable
Income
Tid Refund Marital 
Status 
Taxable 
Income Cheat 
1 Yes Single 60K No 
2 No Married 100K No 
     
3 Yes Married 120K No 
4 No Divorced 95K Yes 
     
5 Yes Divorced 220K No 
6 No Single 85K Yes 
     
7 No Single 90K Yes 
10 
 Cheat
Don’t
Cheat
GenAI and Agentic AI - Prof Durga 
Toshniwal
60 - 80K,
100 - 250K 80 – 100K

[page 16]
Decision Tree Induction
Exceptional 
Conditions:
• If all records traverse 
same path but the class 
label differ, and it is not 
possible to split these 
records further, the node 
is made leaf node & 
class label is that of 
majority of records at the 
node
Refund
No
Marital
Status
?
Single, Divorced
Taxable
Income
GenAI and Agentic AI - Prof Durga 
Toshniwal
Tid Refund Marital 
Status 
Taxable 
Income Cheat 
1 No Single 150K No 
2 No Divorced 65K No 
3 No Single 120K Yes 
4 No Single 220K No 
5 No Divorced 70K Yes 
9 No Single 110K No 
10 No Single 240K Yes 
10 
 
60 - 80K,
100 - 250K

[page 17]
How to do Split - Splitting Based on 
Categorical Attributes
• Multi-way split: Use as many partitions as 
distinct values. 
• Binary split:  Divides values into two 
subsets. Need to find optimal partitioning.
CarType
Family
Sports
Luxury
CarType{Family, 
Luxury} {Sports}
CarType{Sports, 
Luxury} {Family} OR
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 18]
How to determine the Best Split
Own
Car?
C0: 6
C1: 4
C0: 4
C1: 6
C0: 1
C1: 3
C0: 8
C1: 0
C0: 1
C1: 7
Car
Type?
C0: 1
C1: 0
C0: 1
C1: 0
C0: 0
C1: 1
Student
ID?
...
Yes No Family
Sports
Luxury c1
c10
c20
C0: 0
C1: 1...
c11
Class Distribution denotes the fraction of records belonging to a 
class i at a given node t
Before Splitting: 10 records of class 0  denoted by C0,
  10 records of class 1  denoted by C1
Initially before splitting class distribution is (0.5,0.5)
(a)                                            (b)                                       (c)
Which test condition is the best?
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 19]
How to Find the Best Split
B?
Yes No
Node N3 Node N4
A?
Yes No
Node N1 Node N2
Before Splitting:
C0 N10 
C1 N11 
 
 
C0 N20 
C1 N21 
 
 
C0 N30 
C1 N31 
 
 
C0 N40 
C1 N41 
 
 
C0 N00 
C1 N01 
 
 M0
M1 M2 M3 M4
M12 M34
Gain = M0 – M12 vs  M0 – M34
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 20]
Splitting Criteria based on INFO gain
• Entropy at a given node t:
Where  p( j | t) is the relative frequency of class j 
at node t 
– Measures homogeneity of a node. 
−=
j
tjptjptEntropy )|(log)|()( 2
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 21]
Splitting Criteria based on INFO gain
• Entropy at a given node t:
Where  p( j | t) is the relative frequency of class j 
at node t 
– Measures homogeneity of a node. 
• Maximum when records are equally distributed 
among all classes implying least information
• Minimum when all records belong to one class, 
implying most information
−=
j
tjptjptEntropy )|(log)|()( 2
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 22]
Examples for computing Entropy
C1 0 
C2 6 
 
 
C1 2 
C2 4 
 
 
C1 1 
C2 5 
 
 
P(C1) = 0/6 = 0     P(C2) = 6/6 = 1
Entropy = – 0 log 0 – 1 log 1 = – 0 – 0 = 0 
P(C1) = 1/6          P(C2) = 5/6
Entropy = – (1/6) log2 (1/6) – (5/6) log2 (1/6) = 0.65
P(C1) = 2/6          P(C2) = 4/6
Entropy = – (2/6) log2 (2/6) – (4/6) log2 (4/6) = 0.92
−=
j
tjptjptEntropy )|(log)|()( 2
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 23]
Splitting Criteria based on INFO gain
GenAI and Agentic AI - Prof Durga 
Toshniwal
Information Gain: 
  Parent Node, 𝑝 is split into 𝑘 partitions (children)
   𝑛𝑖 is number of records in child node 𝑖
– Choose the split that achieves most reduction 
(maximizes GAIN)
– Used in the ID3 and C4.5 decision tree algorithms


−= 
=
k
i
i
split iEntropyn
npEntropyGAIN
1
)()(

[page 24]
Stopping Criteria for Tree Induction
• Stop expanding a node when all the 
records belong to the same class
• Stop expanding a node when all the 
records have similar attribute values
• Early termination  
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 25]
Decision Tree Based Classification
• Advantages:
– Inexpensive to construct
– Extremely fast at classifying unknown records
– Easy to interpret for small-sized trees
– Accuracy is comparable to other more 
complex classification techniques for many 
simple data sets
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 26]
Classification by Decision Tree Induction
• Domain knowledge and parameter setting 
may not be required so it is good for 
knowledge discovery
• Representation is intuitive and interpretable
• Generally has good accuracy
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 27]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga 
Toshniwal
• A Random Forest is a powerful ensemble machine learning 
technique that uses multiple decision trees to make 
predictions.
• Each tree in the forest is trained on a random subset of the 
data samples and considers a random subset of features.
• The predictions of all trees are then combined, either by voting 
for classification to produce a final prediction.
• Random Forest is an ensemble method, meaning it combines 
the predictions of multiple models (decision trees) to make a 
more accurate prediction than any single model could achieve 
on its own.

[page 28]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga Toshniwal
• Ensemble Method: Ensemble simply means combining 
multiple models.
• Ensemble can be of two types:

[page 29]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga 
Toshniwal
• Random Forest uses Bagging also known as Bootstrap 
Aggregation
• There are multiple decision trees and each decision tree in the forest 
is trained independently on a different subset of the data using a 
technique called "bootstrap aggregating" or "bagging"
• This means that each tree might have a slightly different view of the 
data, leading to a more diverse set of predictions.
• The randomness in Random Forest comes from the following:
Bootstrap Sampling:
• Each tree is trained on a randomly selected samples of the data, 
allowing some samples to be used multiple times  
Feature Randomization:
• A random subset of the available features is considered at a time

[page 30]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga 
Toshniwal
Random Forest uses Bagging also known as Bootstrap sampling. 
A bootstrap sample, is a dataset created by repeatedly drawing from an 
original sample with replacement.
This means that data points can be selected multiple times in the new 
sample, and the new sample has the same size as the original.  
Analogy:
Imagine having a box of balls that are numbered uniquely with ball-ids – 
let this be the original sample with total balls = N
Assume that the box has the property that whenever we pick out any 
particular ball from it, then another ball with the same ball-id is added to 
the box so that it contains all unique ball-ids at any given point in time, this 
is called ball replacement
We want to create a new box of balls with total N balls, 
 
Due to replacement policy, We can end up picking the same ball-id 
multiple times or not pick a ball-id at all for the new box.

[page 31]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga 
Toshniwal
Analogy:
Imagine having a box of balls that are numbered uniquely with ball-ids – 
let this be the original sample with total balls = N
Assume that the box has the property that whenever we pick out any 
particular ball from it, then another ball with the same ball-id is added to 
the box so that it contains all unique ball-ids at any given point in time, this 
is called ball replacement
We want to create a new box of balls with total N balls, 
 
Due to replacement policy, We can end up picking the same ball-id 
multiple times or not pick a ball-id at all for the new box.

[page 32]
Random Forest based Classification
GenAI and Agentic AI - Prof Durga 
Toshniwal
Key aspects of a bootstrap sample:
• Resampling with replacement:
Each data point in the original sample has an equal chance of being 
selected for inclusion in the bootstrap sample.
Some data points may be selected multiple times, while others might not 
be selected at all in a given bootstrap sample.
• Sample size:
The bootstrap sample is typically the same size as the original sample, 
creating a simulated version of the original data.
• Multiple samples:
The process is repeated many times (e.g., 1000 times) to create multiple 
bootstrap samples.
• Purpose:
Improve the performance of machine learning model

[page 33]
Classification in Large Databases 
Using Decision Tree
Scalability Issues –  
• Restriction is that the training tuples must 
reside in memory
• But most often, the real world training 
dataset is so huge that it will not fit in 
memory  
• Decision tree construction thus becomes 
inefficient due to swapping of training tuples 
in & out of memory 
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 34]
Practical Issues of Classification
The errors in a classification model can be 
broadly –
• Training errors
• Generalization errors
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 35]
Practical Issues of Classification
• Training errors
– Also called re-substitution errors or apparent 
errors
– Is the number of misclassification errors on 
training records
• Generalization errors
– Is Expected error of the model on previously 
unseen records
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 36]
Practical Issues of Classification
A good model must have both of these low
A model that fits the training data too well 
can have poorer generalization error than 
a model with a higher training error
Such a situation is called model overfitting
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 37]
Underfitting and Overfitting
Overfitting
Underfitting: when model is too simple, both training and test errors are large, 
model is yet to learn the true structure of the data 
Underfitting
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 38]
Overfitting due to Noise 
Decision boundary is distorted by noise point
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 39]
Overfitting due to Insufficient Examples
Lack of data points in training data may make 
it difficult to predict correctly the class labels 
of that region 
Insufficient number of training records in the 
region causes the decision tree to predict the 
test examples using other training records 
that are irrelevant to the classification task
GenAI and Agentic AI - Prof Durga 
Toshniwal

[page 40]
Overfitting
• Overfitting results in decision trees that are 
more complex than necessary
• Training error no longer provides a good 
estimate of how well the tree will perform 
on previously unseen records
GenAI and Agentic AI - Prof Durga 
Toshniwal