So for those of you who are interested in knowing how the code works.
Stay with me. I will explain that.
So I will reduce this.
Okay.
And let's explain this.
Okay.
So the idea is that we consider each of these pixel observation points.
As a user in the social network, like an imaginative user.
And so, you know, for example, this pixel point here is not a user
in the data set.
But we imagine this pixel point here as a user who has this salary and this age.
And we
apply our classifier on this pixel observation points
on this user here, so that the classifier predicts
if the user is going to buy yes or no, the SUV.
Then once the classifier makes its prediction.
It colonizes the pixel observation points according to the prediction.
So if the prediction is no this pixel user
won by the SUV, then it will colorize in red.
And if the prediction is yes, this pixel user will buy the SUV,
then it will colorize the points in green.
And so we apply that idea on all the pixels in this frame,
so that eventually our classifier will colorize
all the points that he predicted as zero in red,
and all the points that he predicted as one in green.
So now that you get the idea, let's look at our code
here and go through the steps of completing this idea.
Okay.
So first I declare a set equals training set.
That's because, you know,
I want to plot this graph for the training set and the test set.
And since we're using training
set many times in the code, I just replaced it by set here.
So that's when I copy paste the same code for the test set.
I just need to replace test
set by training set only here and not in the whole code.
So basically that's just a shortcut.
And so first we build a grid with X one and x two.
So we take the minimum of the values of the training set minus one.
Because we don't want the points to be squeezed in the graph.
And same for the maximum plus one.
So by doing this we're taking the range of our training set observation points
minus one and plus one so that so that our points are not squished in the graph.
And so we're doing this for the h column
of the training set and the salary column of the training set.
Then by writing this line we are building the grid.
So basically with these three lines we're making the grid here
with all the pixel observation points that are imaginary social network users.
Then, since this grid set is actually a matrix of the two columns age and salary,
but for all the imaginary users that are the pixel observation points,
this is actually a matrix.
So with this line, we just give a name to the columns of this matrix,
which are age and estimated salary.
And then that's where all the magic happens.
Because here that's where we use our classifier
to predict the result
of each of the pixel observation points that are the imaginary pixel users.
So we predict this.
And then, you know, since the predict function returns the probabilities,
we transform it into 1 or 0 result.
So that's why I call it y grid, because it's the predictions
of all the points in the grid.
So that returns the vector of predictions of all the points in the grid.
And then finally we plot the whole graph.
So in this plot we include
all our real users and their real actions.
Read if they didn't buy the car in green, if they bought the car
and we plot the predicted results of all the pixel observation points
that we created when we created the grid.
So that's here.
And so, you know, I'm using the color spring green.
So that is the spring green color and tomato.
That is the tomato color.
And for the real points I just use a green four which is a color
in R and red three.
So this color is green four and this color is red three.
And that's it.
That's the idea behind this code.
It's totally fine if you didn't understand some things in this code.
Because anyway, we're going to use this code as a template for our
next classifier.
And so we'll just have to copy paste this code.
But that's all.
So that was just for those of you who are interested in coding,
who are interested in how we can use code to make such a plot.
But the important thing to understand here is that the logistic regression
is a linear classifier,
which in two dimensions means that it's a linear separator,
and therefore it can make some predictions, like the predictions here
there are incorrect.
All right.
So thank you for watching this R tutorials.
And congratulations.
Now you know how to implement a logistic regression model using R.
You're going to see
that we will need some more powerful classifiers later in our journey.
So I look forward to continue this journey and until then enjoy machine learning.