Lecture 2.1 - AML
Lecture 2.1 - AML
Learning with
TensorFlow
22TCSE532
Lecture_2.1
Introduction to Ensemble Methods
Ensemble methods use multiple models together to make better predictions than a single model can.
Ensemble
Bagging Boosting
● Reduces Overfitting:
○ By using many models, the final prediction is less likely to be overly tailored to the
training data, making it perform better on new data.
● Improves Accuracy:
○ Ensemble methods usually give more accurate results than using a single model
because they combine the strengths of multiple models.
Row Sampling with Replacement
m<n
M1
d1`m - For each and every model we will provide
the sample of the dataset D (with n
records) as d1`m (m is no of records).
M2
- For M2 we will again resample the records
and pick the other sample of records to
Dataset give input to them.
d2`m
M3 - This is basically called as row sampling
n with replacement.
Mn
- Take the test data d`` and get the
d`` predictions(output).
M1 1
m<n - Once we get the output for all
d1`m
different models, then we will
d`` (Test Data) apply voting classifier.
M2 0 - Now majority of the votes given
Dataset d2`m 1 as output will be considered final
output.
M3 1
n
BOOTSTRAP AGGREGATION
Mn 1
d`` 1
M1
m<n
d1`m
BOOTSTRAP AGGREGATION
Mn 1
d`` 1
DT1
m<n
r ’X n’ Base learner is Decision
Tree.
d`` (Test Data) DT2 0
r Dataset 1
DT3 1
n
n = no of columns 1
DTn
r = no of rows
Whenever we create decision tree to it’s complete depth
• Low BIAS(means it will get trained so well on training dataset such that training
error will be very less)
• High VARIANCE(for the test data these decision trees will be prone to give
larger amount of errors)
d``
DT1 1.14 We will either take
m<n mean or median of
r ’X n’
d`` (Test Data) the outputs. It
DT2 0.95 depends upon the
r Dataset
0.75 distribution of the
output.
DT3 1.05
n Hyperparameter = No of
Decision Trees
n = no of columns 0.87
DTn
r = no of rows
What is Out of bag evaluation in Random Forest(Bagging)?
d`` 1
DT1
m<n OOB Score
r ’X n’
d`` (Test Data)
DT2 0
1000 r Dataset 1
DT3 1
k
Out of n
Bag(OOB)
n = no of columns 1
DTn
r = no of rows
Data
Train Test
Train Validation
⅔*n ⅓*n
If I will set the OOB parameter to TRUE, OOB data will
become/considered as a Validation data.
● Process:
○ Models are trained one after another, each trying to correct the
mistakes of the previous one.
○ Combines weak learners to form a strong learner.
1. Initialization:
○ Start with an initial model trained on the data.
2. Sequential Training:
○ Train a series of models sequentially.
○ Each new model focuses on the errors made by
the previous models.
3. Weight Adjustment:
○ Increase the weight of incorrectly predicted
examples to emphasize their importance in
subsequent training.
4. Combination:
○ Combine the predictions of all models to make
the final prediction (e.g., weighted sum for
regression, majority voting for classification).
What is AdaBoost?(Adaptive Boosting)
Stumps
Sample
weight
Calculating sample
weight
w= 1/n
Entropy or gini coefficient or we can
use both to select the stump, the one Selecting a base
with least value will be selected learner
f1 f2 f3
Let say DT with f1 (employee id) is
selected
f1
5
1
Now we need to find the total error for the
record which is incorrectly classified Finding Total Error
= ½ ln [5]
= 0.804
Finding the
Why we have calculated the total error and performance of the
performance of the stump? stump
Because we need to update the sample weight.
The weight for the correct predictions will be
reduced and wrong predictions increase before
sending data to 2nd base learner.
Now we have to increase the weight of wrong classified record
and we have to decrease the weight for the correctly classified
record.
Update the weight of incorrectly classified point
Update Weight
Update the weight of incorrectly classified point
Update Weight
We can see that sample weight adds up to 1 but the updated weight does not.
Divide by sum of
Because summation of all the values under updated weight is updated weights
not 1 therefore i.e 0.72 Normalizing Updated
Weights
Now we will be using the Normalised weights and select the all
misclassified records for the second base learner to learn .
Choosing the Second Base Learner
Model Testing: This is the final evaluation step, performed after the model is trained
and validated. It uses a test set (which the model has never seen before) to measure
the model's true performance in a real-world scenario. The results on the test set
provide an unbiased estimate of how the model will perform on new, unseen data.