Now, the other very
important thing to understand is that these are two prediction regions
separated by a straight line, which is the straight line.
Here.
And the straight line is called the prediction boundary,
because it's the boundary between the two prediction regions.
And the fact that it's a straight line is not random.
It is for a particular reason.
And that's the thing very important to understand,
because that's the essence of logistic regression.
If the prediction boundary is a straight line here,
that's because our logistic regression classifier is a linear classifier.
That means that here, since we are in two dimensions, you know,
because we have two independent variable the age and the estimated salary.
So we are in two dimensions.
Then since the logistic regression classifier is a linear classifier,
then the prediction boundary separator here can only be a straight line.
If we were in three dimensions then it would be
a straight plan separating two spaces.
But here in two dimensions it's a straight line
and it will always be a straight line.
If your classifier is a linear classifier, but you will see later
that when we build non linear classifiers,
then the prediction boundary separator won't be a straight line anymore.
I won't tell you more right now and I will let you wait for the surprise.
So here we can clearly see that our logistic regression classifier manages
to catch most of the users who didn't buy the SUV in the red region here,
and most of the users who bought the SUV in the green region here.
So it actually did a pretty good job.
However, it seems to have trouble catching some green users here
who in spite of their low salary, but the luxury SUV,
as well as those other green users here who also bought the luxury SUV
because as you can see,
this green points here and those here are in the red region,
which is the region where our classifier predicts
that the users don't buy the SUV.
And those incorrect predictions are due specifically
to the fact that our classifier is a linear classifier.
And because our users are not linearly distributed,
if they were linearly distributed, then we will have all the green points
here in the space and all the red points here in this space.
And then the linear classifier with a straight line could
perfectly separate all the red points here, and all the green points here.
But here we have some rebellious points who are not in the wanted linear regions.
And because our classifier has a linear straight line separator,
that's why it has trouble catching those users here and those here.
You can clearly see that even if you try to rotate this straight
line here, well, you will always have some green points in the wrong category.
For example, if we try to rotate here this way, like putting it down, well
okay, we will catch these green points here and the right green region here.
But since we rotated down we will take more green users here
because this will go up and more green users here will be in the red region.
So that's the best separator.
The logistic regression classifier could find.
And it couldn't do better
because it can only be a straight line separating these two regions.
Because to catch those users, the green users here and the green users
here in the red category that is the green region are classified.
We need to make some kind of a curve here to, you know, classify
correctly those green users here and here and place them in the green region.
And that would prevent our classroom from making this incorrect predictions here
because it is a straight line with a curve.
Here we would catch all the red users, probably in the red region
and all the green users in the green region.
So that would make an awesome classifier.
And you will see
how our nonlinear classifiers will make a terrific job in doing this.
I can't wait to show you this.
Okay.
And now eventually, the last thing very important to understand is that
this is the training set.
This is a training set.
So that means that
our classifier learns how to classify based on these informations here.
So I would hold my breath a few more seconds until I find out
if our logistic regression classifier can manage to make good predictions
of new observations, that is, to classify new users into the right regions,
which, by the way, are fixed regions here, because these are the regions
generated by the learning experience of our logistic regression classifier,
and therefore won't change if we look at some new observations.
That is, new social network users,
and that's what we are about to find out on the test set.
So hold on.
So it's very simple.
We're just going to copy all this code section here.
Paste it here.
And I'm just going to change the training set here.
My test set.
Same here I change training set by test set.
And that's all.
That's all because I structured the codes in such a way
that we only need to change the training set into the test set here.
To plot this graph on a specific set.
However, let's change the title here because we want to specify
that it's the test set and it's ready.
So let's select this and execute.
Let's see what happens.
And here are the results of the test set.
So that's not too bad.
That's not too bad. Because as we can see
the major the majority of red points are in the right region.
That means the region predicted to be zero and the majority of green points
are in the right region.
As for the
training set, there are some observations that were incorrectly predicted.
That's normal.
That's because it's a linear classifier and it cannot make a curve here.
Catching all the right guys.
All right so that's it for the interpretation of the graph.
I can't wait to show you how we can make more powerful classifiers.
And of course these are going to be nonlinear classifiers.