And now we're eventually at the final round
of our logistic regression model, which is the fun part, because we're going
to visualize the training set results as well as the test set results.
And basically, we're going to make a plot that will represent
everything that is happening with our logistic regression model.
So let's make this chart.
I'm going to do like in Python.
I'm going to take the code that I've prepared and paste it here.
I will select and execute the code.
And then for those of you who are interested
in the idea behind the code, that is how the code plots the graph.
I will explain how the code works at the end of this tutorial.
Okay, so right now I'm going to paste the code.
Here we go.
Then this code contains 15 lines of code.
That was also the case in Python.
And that's because it's the exact same code based on the same idea.
And I will explain this idea.
That means I will explain how this code works at the end of this tutorial.
But for now let's select this code and let's see what happens.
So command and Control plus enter to execute.
And let's wait.
It's taking a little time. That's normal.
But it's going to plot something.
There it is.
There it is. That's the plot.
Okay.
So for those of you
who follow the Python tutorial, we obtain exactly the same plot.
So let's describe this plot.
I'm going to enlarge this.
Okay.
So let's analyze this graph step by step.
First let's focus on all the points. Here.
We can see that we have some red points.
And some green points.
So all these points that we see on this graph
are the observation points of our training set.
That is these are all the users of the social network
that were selected to go to the training set.
And each of these users here is characterized by its age.
Here on the x axis and its estimated salary here on the y axis.
Now we can see that there are some red points here
and some green points here.
The red points are the training set observations for which the dependent
variable purchased is equal to zero, and the green points are the training set.
Observations for which the dependent variable purchased is equal to one.
That means that the red points here are the users
who didn't buy the SUV, and the green points.
Here are the users who bought who actually bought the SUV.
So now, as a first step of analysis, let's give an interpretation
of what we observe here with these users.
Okay.
So first we can see that the users who are young with a low estimated salary.
So these users here actually didn't buy the SUV.
Then if we look at the users who are older and with a higher estimated salary,
well, we can see that most of these users actually bought the SUV.
And it actually makes sense because the SUV is more like a family car
and therefore more interesting
for these older users here with a high estimated salary.
Besides, we can also see that some older people,
even with a low estimated salary, actually bought the SUV,
because we can see that we have some green points here
that correspond to an age above the average.
The average is here,
but an estimated salary below the average because the average is here.
Okay.
So these guys, these older guys, although they have a low estimated salary,
actually bought the SUV, probably because they've been saving up some money.
Or maybe they finished paying of their mortgage.
I don't know, but what's for sure is that they couldn't resist buying this
very cool luxury SUV offered at a ridiculously low price.
And on the other
hand, we can also see that there are some young people here
with a high estimated salary who actually bought the SUV.
You know, maybe because it's a very cool SUV
and they want to impress their friends and take them into road trips.
Or maybe they already have a family, I don't know.
Anyway, they bought the SUV.
Actually, there are a lot of buyers, so this must be a very cool and cheap SUV.
Okay, and now what is the goal of classification?
Now we're talking machine learning.
Why are we making some classifiers?
And what will classifiers do.
And least what are we trying to make them do for this particular business problem.
Well the goal here is to classify
the right users into the right categories.
That is, we are trying to make a classifier
that will catch the right users into the right category,
which are yes, they buy the SUV and no, they don't buy the SUV.
And we represented the way our classifier catches these users
by plotting what I called the prediction regions.
And so the prediction regions are the two regions that we see on this graph.
This red one here and this green one here.
And the red prediction region is the region where our classifier catches
all the users that don't buy the SUV.
And the green prediction region
is the region where a classifier catches all the users that buy the SUV.
But be careful.
This is according to the classifier that is for each user of this
red prediction region here.
Our logistic regression classifier predicts that the user doesn't
buy the SUV.
And for each user of this green prediction region here,
our classifier will predict that the user buys the SUV.
So that makes an awesome tool because for each
new user of the social network, well, a logistic regression
classifier will tell based on its age and its estimated salary.
If this user belongs to this red prediction region here,
and therefore doesn't buy the SUV, or if this user belongs
to this green prediction region here and therefore buys the SUV.