Hello and welcome back.
Today we've got a very exciting tutorial.
We're talking about the logistic regression.
The logistic regression is used to predict a categorical
dependent variable from a number of independent variables.
So the key difference to a linear regression
here is that we're not predicting a continuous variable.
We're predicting a categorical variable.
For example you might be working for an insurance company.
And you want to predict will somebody purchase
the health insurance that your company is offering.
Yes or no.
And it's a very simple yes or no.
it's a categorical variable.
And you might want to be predicting this dependent variable,
based on an, an independent variable such as age.
So depending on their age, will they purchase,
the health insurance plan that your company is offering?
So on the x axis we would have age.
On the y axis we would have yes or no.
Did they take up the offer or not?
Let's say our x axis is somewhere between 18 years of age and 60 years of age.
And our y axis simply has a binary outcomes.
Yes and no.
So there's no in between this either yes or no.
So we're going to just add this horizontal line for illustrative purposes.
So what will our data set look like.
Let's say we've got certain number of observations in our data set.
So we know people's age and we know, when they were exposed to the offer,
whether they purchased or didn't.
So these people over here didn't purchase, the health insurance.
And these people over here
did purchase the health insurance, and that's our data set.
So as you can see, it's very different.
This plot looks very different to what we were working with in the linear
regression in tutorials.
So we can't simply draw a linear regression
line as sloped a line through these points.
It makes no sense.
So that's why the equation for logistic regression is slightly different.
Here it is.
So, here on the left we've got,
instead of y, we've got, a logarithm.
And then on the right we've got, the same, part as we saw before,
the important value to us here is P, and that is the probability
that we'll be, working with just now.
We'll see it in action.
So let's look at the logistic regression curve.
The logistic regression curve looks like this.
And it's also called the sigmoid curve.
And how does this work in action.
Well let's say we have two new observations.
Let's say we've built this model based on this data.
we have a logistic regression.
How will it apply to new observations.
Well let's say we have two new observations.
Somebody of age 35 and somebody of age 45.
what we do is we will need to project these values
onto our logistic regression, find out where they fit there.
And the logistic regression will give us probabilities.
So, this value everything here is between 0 and 1.
So no is a zero.
Yes is a one.
And in between are the probabilities.
So the logistic regression gives us probabilities of somebody saying yes.
So somebody's taking up that offer.
So for the 35 year old it's a 42% chance
that they will take up the offer based on this model.
So this is what the model is
predicting is predicting a 42% chance they will take up the offer.
And for the 45 year old, there's an 81% chance they'll take up though.
So we could stop there.
That is the P.
That is a probability that we see in the equation on the left.
that's hidden inside that logarithm.
So we could stop there and we could use these probabilities.
Not in some use cases.
That's what the logistic regression is used for.
We, we just deal with the probabilities once we have them.
But in most cases we want a binary outcome, a yes or no outcome.
And so for those situations, we split our curve into two.
I'll plug in to do anything above this line, this middle line,
anything above with a probability of 50% or higher
will be projected into a yes into a binary one.
And anything below the 50% line will be projected into a no, a binary zero.
How points would end up here?
So based on this logistic regression, we would make the conclusion
that the 35 year old would not purchase our insurance
plan and the 45 year old would purchase our insurance plan.
And just like with linear regression, you can have multiple independent
variables.
So for instance, age, income, level of education,
how big their families or whether they have a family or they're single
and many other types of variables can be added depending on the, use case.
And our equation will look like this in this situation.
So there you go.
That's logistic regression in a nutshell.
I look forward to seeing you next time.
And until then enjoy machine learning.