All right, my friends,
here we are at the final step of this implementation
and actually the most exciting one, because this is the step where
we're going to visualize it on a nice 2D plot, the prediction curve
and the prediction regions of the logistic regression model.
All right.
So more specifically, what we're about to plot
is a two dimensional plot with therefore
two axes x and y on the x axis.
You will have the first feature corresponding to the h, and on the y axis
you'll have the second feature corresponding to the estimated salary,
and therefore each of the observation points you will see on the 2D
plot will correspond to a specific customer.
It will either be a customer of the training set.
You know, on the plot of the training set results,
or a customer of the test set on the plot of the test result.
And what is most interesting to see in
this plot will be the prediction regions, meaning the regions
where our logistic regression model predicts the class zero,
meaning the customers didn't buy the SUV, and the other region
where our logistic regression model predicts the class one,
meaning the customer, but the SUV.
And lastly, what will be really interesting to see
is the curve separating these two regions.
You know, the region of the prediction zero and the region of the predictions
one. And this is exactly how we are going to see the difference
between linear classifiers and nonlinear classifiers.
So here we only starting with one classification model logistic regression.
So we won't compare that yet.
But you will see in the next sections of this part that the prediction
boundary between these two prediction regions will be different
depending on whether or not your classifier is linear.
All right. So I can't wait to show you this.
And let's start first by visualizing these training
set and test results for the logistic regression model.
All right.
So the code to visualize this is actually pretty advanced.
And not only it is pretty advanced, but also you will
probably never use it again in your career.
Or let's say you will never have to implement that again.
Why is that?
It's because in your career you will mostly work
with data sets, having many features, you know, more than two.
And here the only reason why we have a data set of two features
is so that we can be able to visualize indeed, well, these prediction regions
and prediction boundary,
because indeed, in order to visualize this, we need maximum two features,
because one feature corresponds to one dimension in this plot.
So what I suggest is that we don't waste too much time,
you know, understanding the whole code and re-implemented ourselves.
Because really, I'm going to show it to you right away, you know,
on the original logistic regression implementation,
you will see that the code is pretty advanced.
You know, it's not like plotting a regression curve like we did in part two.
So that's the test results.
Let me show you the training set results.
All right.
So that's the code.
You see it's uses a lot of tricks to plot all these observation points.
Prediction regions and prediction boundary.
So if you want to have a look at it and understand it fine.
But really for the others it's totally okay if we don't cover this code in detail
because this is only for training purposes.
Just so that I can show you
the differences between linear classifiers and nonlinear classifiers,
and you will probably never use that again in your future machine learning project.
However, what I will do just now is explain how it's done.
Basically, what we do is we create, as you can see, a grid
which is basically this frame here containing all the edges of your features
and all the estimated salaries, you know, the ranges,
and you create this grid with a high density, meaning that
the pixels of this grid are not separated one by one, but every oh point 25.
So here, for example, for the age, it goes this way.
It goes from 10 to 10.20 5 to 10.5 to 10.75 to 11, etcetera.
Up to 69, 69.25, 69.5,
69.75, 70 okay, and same for the estimated salary.
It goes from 20,000, then 20,000.25, 20,000.5, etc.
up to somewhere around 149,000 149,000.25.
You see, so resulting in having super dense points inside this grid
and then the trick, you know, what we did is not only
we plotted all the real observation points in the grid.
So all the points that you see here are the customers of either your training sets
and then later on your test set, the green points are, of course,
the customers who bought the SUV, you know, represented by one here.
And the red points are, of course, the customers who didn't buy
the SUV represented by zero here.
Okay, so all the points are your observation points.
Your customers.
And then so the trick in order to plot the prediction regions
and therefore that prediction boundary here separating the two regions
is to apply to predict method
onto each of these dense points in the grid,
so that all the dense points here, you know, in this region
were actually predicted to be zero, meaning all the customers,
you know, other customers inside this region are predicted not to buy the SUV.
And all the observation points in this green
region are actually predicted to by the SUV.
So you see how this works. That's the trick.
And then really you don't have to understand
all the techniques used to implement this, because once again,
you will probably never have to implement that kind of code in your career.