Professional Documents
Culture Documents
Classification
Classification
Learning –
Classification
Dr. Satish Kumar
Associate Professor,
Department of Robotics & Automation
Symbiosis Institute of Technology,
Pune
What is Machine Learning?
Applications of ML
Search Smart Email
Video Game
Engines Phones Programs
Adaptive Autonomous
Robots Banks
Telescopes Car
Disease
Diagnosis
• Algorithm: A set of rules and statistical techniques used to
learn patterns from data and draw significant information
from it.
• Model: A model is trained by using a Machine Learning
Algorithm.
Machine • Predictor Variable: It is a feature(s) of the data that can be
used to predict the output.
Learning • Response Variable: It is the feature or the output variable
that needs to be predicted by using the predictor variable(s).
Terminology • Training Data: The training data helps the model to
identify key trends and patterns essential to predict the
output.
• Validation Data: it is used to evaluate the model, to fine
tune the model hyperparameters
• Testing Data: It is used to evaluate the model once the
model is completely trained.
Various Datasets for ML Model
Train Validation Test
Various Datasets for ML Model
• Determine a classification rule that predicts the class of any input data from the values
of its attributes
Classification Problems in Real Life
Handwritten
Image
Email spam digit
segmentation
recognition
Multi-Class Classification
Types of
Classificaiton Multi-Label Classification
Imbalanced Classification
Binary Classification
Train a classifier
(𝑖)
ℎ𝜃 = 𝑃(𝑦 = 𝑖|𝑥; 𝜃) (i=1,2,3)
One or more class labels may be predicted for
each input sample
Multi-Label
Classification
Examples: Photo classification
• A classification algorithm (Classifier) that makes classification based on a linear predictor function combining
a set of weights with the feature vector
• y = f(σ𝑖𝑤𝑖𝑥𝑖)
Perceptron
Logistic regression
Linear
Classifiers Naïve bayes
Binomial classification
• If the activation is
• Positive –output 1
• Negative –output -1
Perceptron…(Contd.)
Learning Weights in Perceptron
The sigmoid function is a mathematical function used to map the predicted values to probabilities.
It maps any real value into another value within a range of 0 and 1.
The value of the logistic regression must be between 0 and 1, which cannot go beyond this limit, so it
forms a curve like the "S" form. The S-form curve is called the Sigmoid function or the logistic function.
In logistic regression, we use the concept of the threshold value, which defines the probability of either 0
or 1. Such as values above the threshold value tends to 1, and a value below the threshold values tends to
0.
Logistic Regression Equation:
• The Logistic regression equation can be obtained from the Linear Regression equation. The
mathematical steps to get Logistic Regression equations are given below:
• We know the equation of the straight line can be written as:
Where , 𝑧 = β𝑇 𝑥𝑖
Therefore,
• On the basis of the categories, Logistic Regression can be classified into three types:
• Binomial:
• In binomial Logistic regression, there can be only two possible types of the dependent variables,
• Ex- 0 or 1, Pass or Fail, etc.
• Multinomial:
• In multinomial Logistic regression, there can be 3 or more possible unordered types of the dependent
variable,
• Ex- "cat", "dogs", or "sheep"
• Ordinal:
• In ordinal Logistic regression, there can be 3 or more possible ordered types of dependent variables,
• Ex - "low", "Medium", or "High".
Evaluation Metrics for
Classification
• Confusion matrix
Evaluation • Accuracy
•
Metrics •
Log-loss
AUC-ROC
Confusion Matrix
• Confusion Matrix is a performance
measurement for machine learning
classification.
• It is a table with 4 different combinations
of predicted and actual values.
• It is extremely useful for measuring
Recall, Precision, Specificity, Accuracy,
and most importantly AUC-ROC curves.
Source: https://towardsdatascience.com/understanding-confusion-matrix-a9ad42dcfd62
Understanding Confusion Matrix
• True Positive (TP)
• Interpretation: You predicted positive and it’s true.
• You predicted that a fruit is an Apple, and it is an Apple.
Classification
report Recall
Using
Confusion F measure
Matrix
Accuracy
Recall (Sensitivity or True Positive
Rate)
• Out of the total positive, what percentage are
predicted positive. It is the same as TPR (true
positive rate) called as recall value
• The number of true positives divided by the
total number of actual positives.
Precision
2 2 1
= (2+2)=4 = 2
2 2
= (2+1)= 3
(2+2) 4
= (2+2+1+2)=7
AUC-ROC curve
AUC - ROC Curve
Source: https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5
Receiver Operator Characteristic (ROC) Curve:
Source: https://www.analyticsvidhya.com/blog/2020/06/auc-roc-curve-machine-learning/
Area Under the Curve (AUC)
Source: https://towardsdatascience.com/understanding-auc-roc-curve-68b2303cc9c5
AUC Curve (AUC = 1)
Source: https://www.analyticsvidhya.com/blog/2020/06/auc-roc-curve-machine-learning/
AUC Curve
(0.5<AUC<1)
Source: https://www.analyticsvidhya.com/blog/2020/06/auc-roc-curve-machine-learning/
AUC Curve (AUC=0.5)
Source: https://www.analyticsvidhya.com/blog/2020/06/auc-roc-curve-machine-learning/
Log-loss is indicative of how close the
prediction probability is to the
Log Loss corresponding actual/true value (0 or 1 in
(Logistic Loss case of binary classification).
or
More the predicted probability diverges
Cross Entropy Loss) from the actual value, the higher is the log-
loss value
Source: https://towardsdatascience.com/intuition-behind-log-loss-score-4e0c9979680a
How is log-loss value calculated
Where,
• ‘I’ is the given observation/record,
• ‘y’ is the actual/true value,
• ‘p’ is the prediction probability, and
• ‘ln’ refers to the natural logarithm (logarithmic value using base of e)
of a number.
Log-loss value
• Example
▪ Predicted probabilities ▪ Corrected probabilities
Log-loss value
Solution:
• To compensate for this negative value,
use a negative average of the values
K-NN algorithm stores all the available data and classifies a new data
point based on the similarity.
When new data points come in, the algorithm will try to predict that to
the nearest of the boundary line.
K-Nearest Neighbor Classifier
12/28/2021 65
How does KNN Work?
Source: https://www.javatpoint.com/k-nearest-neighbor-algorithm-for-machine-learning
How does KNN Work?
For classification: A class label assigned to the majority of K Nearest Neighbors from the training
dataset is considered as a predicted class for the new data point.
For regression: Mean or median of continuous values assigned to K Nearest Neighbors from
training dataset is a predicted continuous value for our new data point
12/28/2021 67
Choosing the Right Value of K
It’s very important to have the right k-value
when analyzing the dataset to avoid
overfitting and underfitting of the dataset.
Suggestions to choose K
K value should be odd
Domain knowledge is
while considering
Using error curves very useful in choosing
binary(two-class)
the K value.
classification
Support Vector
Machine
Support Vector
Machine
• Support Vector Machine or SVM is one
of the most popular Supervised
Learning algorithms.
• It can be use for Classification as well as
Regression problems.
• The goal of the SVM algorithm is to
create the best line or decision
boundary that can segregate n-
dimensional space into classes so that
we can easily put the new data point in
the correct category in the future.
• This best decision boundary is called a
hyperplane.
Source: https://www.javatpoint.com/machine-learning-support-vector-machine-algorithm
Hyper-plane
the
If the number of input features is
hyperplane three, then the hyperplane becomes a
2-D plane.
Source: https://www.geeksforgeeks.org/support-vector-machine-algorithm/
Selecting the best hyper-
plane
• when we are choosing optimal hyperplane we will choose one among set of hyperplane
which is highest distance from the closest data points.
• If optimal hyperplane is very close to data points then margin will be very small and it
will generalize well for training data but when an unseen data will come it will fail to
generalize well
• So our goal is to maximize the margin so that our classifier is able to generalize well for
unseen instances.
• So, In SVM our goal is to choose an optimal hyperplane which maximizes the
margin.
Decision Tree
Classification
Decision Tree
Classification
• Decision Tree is a Supervised learning
technique that can be used for both classification
and Regression problems, but mostly it is
preferred for solving Classification problems.
• There are two nodes, which are the Decision
Node and Leaf Node.
• Decision nodes are used to make any decision
and have multiple branches,
• Whereas Leaf nodes are the output of those
decisions and do not contain any further
branches.
Source: https://www.javatpoint.com/machine-learning-decision-tree-classification-algorithm
Root Node: Root node is from where the decision tree starts. It
represents the entire dataset, which further gets divided into two or more
homogeneous sets.
Leaf Node: Leaf nodes are the final output node, and the tree cannot
be segregated further after getting a leaf node.
Parent/Child node: The root node of the tree is called the parent
node, and other nodes are called the child nodes.
Gini Index (Gini Impurity)
Information Gain
Attribute
Selection
Measures Chi-square
Reduction in Variance
It builds decision trees on different samples and takes their majority vote for classification
and average in case of regression.
Random Forest is a classifier that contains a number of decision trees on various subsets of
the given dataset
The greater number of trees in the forest leads to higher accuracy and prevents the problem
of overfitting
Working of Each individual tree in the random forest spits out a class
Random Forest prediction and the class with the most votes becomes our
model’s prediction
Classifier
Working of Random Forest Classifier
Two phases
Steps
Disadvantages
Deep decision trees may suffer from overfitting, but random forests
prevents overfitting by creating trees on random subsets.
Ensemble Method
Bagging
Ensemble Methods • It creates a different training subset from
sample training data with replacement &
the final output is based on majority voting.
• For example, Random Forest.
Boosting
• It combines weak learners into strong
learners by creating sequential models such
that the final model has the highest
accuracy.
• For example, ADA BOOST, XG BOOST
Bagging and
Boosting
Source: https://www.analyticsvidhya.com/blog/2021/06/understanding-randomforest
• Bagging, also known
as Bootstrap Aggregation is the ensemble
Bagging technique used by random forest.
• Bagging chooses a random sample from
the data set.
• Hence each model is generated from the
samples (Bootstrap Samples) provided by
the Original Data with replacement
known as row sampling.
• This step of row sampling with
replacement is called bootstrap.
• Now each model is trained independently
which generates results.
• The final output is based on majority
voting after combining the results of all
models.
• This step which involves combining all
the results and generating output based on
majority voting is known as aggregation.
Advantages and Disadvantages of Bagging
Advantages
Disadvantages
Source: https://www.analyticsvidhya.com/blog/2021/06/understanding-random-forest
Boosting
Source: https://www.geeksforgeeks.org/xgboost/
Examples of Boosting Techniques
XG
Ada
Gradient Boost(Xtreme
Boost(Adaptive
Boosting Gradient
Boosting)
Boosting)
Advantages and Disadvantages of Boosting
• Sensitive to outliers
Disadvantages • It is almost impossible to scale up
Similarities between Bagging and Boosting
Both make the final decision by averaging the N learners (or taking the majority of
them i.e Majority Voting).