11-Logistic Regression
11-Logistic Regression
Logistic Regression
• Logistic regression is a statistical method used for binary classification
problems in machine learning.
• It works by modelling the probability that a given data point belongs to
one of two classes (e.g., 0 or 1, yes or no) based on the values of one or
more input features.
• Logistic regression algorithm can be applied to a problem statement
when two classes in the problem are linearly separable, i.e., they can be
divided by a straight line.
Why not Linear Regression
• Can we solve the classification problem using linear regression?
Why not Linear Regression
• Now, to solve this kind of problem using linear regression, our objective
is to draw the best-fit line so that the value of the loss function is
minimum
• Y=mx+c is the equation of the line which will divide the points into two
classes.
• If you set the condition that whenever the value of y >=.5, the person is
obese, otherwise the person is not obese.
Why not Linear Regression
• Now if a person with weight 60 comes then we find that y< 0.5, and we
will say that person is not obese.
• So, this means that with the help of linear regression we can classify
properly then question arises what is the need of logistic regression.
Why not Linear Regression
• To understand the need for logistic regression, we added one more
person to the dataset with a weight of 140.
Why not Linear Regression
• Now we have redrawn our new best-fit line due to the addition of a new
point.
• But this has resulted in misclassification as the person with weights like
75, 80, 85, and 100 are now on the left side and their corresponding
value of y is less than 0.5, and we declare them as not obese.
• So, this will result in a higher error rate.
• Also, the value of y can be greater than 1 and less than 0.
Why not Linear Regression
• So, the two important reasons why linear regression can’t be used for
classification problems are as follows:
• Whenever we have a lot of outlier points in the dataset best fit line will completely
deviate and it will give multiple incorrect results.
• Output value is probability but using linear regression, it can be greater than one
and less than zero.
• To solve the above 2 issues, we use logistic regression in place of linear
regression.
Sigmoid Function
• The sigmoid function maps the input to a value between 0 and 1. It is
given by: σ(x) = 1 / (1 + exp(-x))
• The sigmoid function was historically popular but is less common now
due to the vanishing gradient problem as it squashes the output.
• The sigmoid function is commonly used in the output layer of a binary
classification problem.
Logistic Regression-Hypothesis
Interpretation of Hypothesis Output
Decision Boundary
Decision Boundary: Linear
Decision Boundary: Non-Linear
Decision Boundary: Non-Linear
Cost Function
Cost Function
Cost Function
Cost Function
Cost Function
Gradient Descent
Gradient Descent
Multi-Class Classification: One vs All
Multi-Class Classification: One vs All
Multi-Class Classification: One vs All
Multi-Class Classification: One vs All
Multi-Class Classification: One vs All