Understanding— Logistic Regression within 5min 🐱‍🏍

Sri Vigneshwar DJ
3 min readDec 23, 2020

Considering a dataset, where you need to classify events or classes like pass/fail, true/false, win/lose, healthy/sick.. etc, logistic regression will be a great choice to use. Logistic regression is a statistical model that used a logistic function or sigmoid function to model a binary dependent variable.

Disney+ (Source: https://unsplash.com/photos/n1amn-SHKzw)

To understand when to use Logistic Regression, let’s assume that you are a senior Data Scientist at Disney+, your job is to find which age group of people respond to the advertisement campaign for the new movie Housefull 4.

You were given a dataset comprised of a campaign conducted for Houseful 3 and their results (which age group people responded positively). So it's your responsibility to find what is the right age group of people to be targeted for advertising Houseful 4.

Houseful 4 (Source: https://www.hotstar.com/in/movies/housefull-4/1260014263)

Let’s look at the dataset first 👇

Here we can see the problem, we can just fit a line like this and make it a classification problem, We can!!!😁, but the results will be worst 👈. Using Logistic regression we can able to draw the best-fit line for the given dataset using the sigmoid function.

The MATH 🐱‍🚀 behind Logistic Regression

Model:

Output: 0 or 1 , True or False

Hypothesis: Z = WX + B

hΘ(x) = sigmoid (Z)

The hypothesis of logistic regression, its cost function ranges between 0 and 1. The sigmoid function is used to predict the probability.

Logistic Function or Sigmoid Function:

Let’s first understand how to draw a nonlinear line to classify the dataset, Simply sigmoid function converts the real value into another value like between 0 and 1.

Sigmoid function formula

Sigmoid does the magic !!! 🧛‍♂️

Sigmoid function graph

Simple derivation, from linear regression 👇

Understanding the relation between Linear Regression and Logistic Regression is important.

While using linear regression we used the formula of the hypothesis i.e.

hΘ(x) = β₀ + β₁X

and For logistic regression, we will modify linear regression’s formula a bit i.e. (See Fig 3 derivation) 👇

Derivation
The hypothesis of Logistic Regression

Cost Function:

You might have learned about the cost function in simple linear regression, the cost J(θ) and minimizing it help in achieving the best model and high accuracy.

Cost Function

But in logistic regression, if we use linear regression’s cost function, then it will end up in a nonlinear convex graph which of no use and will have many local minima.

Cost Function of Logistic Regression:

Cost function Logistic regression

And the graph looks like 👇

Source: https://www.geeksforgeeks.org/ml-cost-function-in-logistic-regression/

Conclusion:

Thanks for reading my blog, I really appreciate it🙏. I hope this blog helps you to understand Logistic Regression.

--

--