All right.
So let's do this. Let's create a new code cell.
And now the first thing that we have to do is called the matplotlib
dot pyplot module, which has a shortcut plt.
Then from this module we're going to call first the scatter function
which will allow to first, you know, display on a 2D plot
the different points of coordinates containing the real results.
You know, the real position levels going from 1 to 10 and the real salaries.
So that's what we are plotting first.
And then we'll plot the predictions.
And so well here we have to input for the coordinates
of these real points containing the real position levels in real salaries.
And on the x axis we have of course the position levels.
Therefore the x coordinates will be x.
You know all the position levels contained in x.
And then on the y axis will have the salaries the real ones.
And therefore the y coordinates will be.
Y'all right.
And then remember we need to add a color
and we'll choose like last time red.
Perfect. So that's for the real results.
And now we're going to plot the predictions.
And to do that well we're going to call PLT again
matplotlib.pyplot from which we're going to call the plot method.
Because this time we're actually going to plot that regression
line, you know, in blue like in simple linear regression.
And then for polynomial regression,
you will see that it's not a line, but it will be actually a curve.
And still we will use the plot function for that.
So again we have to enter the coordinates of the different points of this line.
And for these coordinates
well first the x coordinates are still x the position levels.
But then the y coordinates will be of course the predicted salaries.
You know, instead of the real salaries.
And to get them well we simply need to call our line
req object not line rec two.
You know, line rec two is for the polynomial regression model.
Line is for the linear regression model.
And so Lin rec from which we're going to call that predict
method applied of course to X right.
Containing the position levels of the matrix of features x.
All right. And then we add a color.
And like last time we'll choose the color blue.
All right blue.
And then we'll just improve or enhance
our graph by adding a title an x label and a y label.
And finally displayed so you know how to do this
we call first plt then the title function.
So here we're going to add a funny title like and quote.
Of course truth or fluff right.
This is the simple scenario I invented for this case study.
And then we're going to precise that it's linear regression.
You know the linear regression model okay good good title.
Now an X label.
So here again plt dot x label.
And we'll choose.
You know something simple like position level okay perfect.
Then a y label.
So I'm calling the y label function.
And we're going to enter salary because on the
y axis are all the salaries the real ones or the predicted ones.
And finally remember that we have to show the graph by using this show function.
Perfect.
And there we go.
We're already ready to visualize the linear regression results.
Are you ready?
I'm going to close this so that we can see it very well.
All right let's make sure I didn't make any mistake.
Yeah it seems all good.
So now let's press play and here we go.
This is the linear regression results.
Let's scroll down a bit.
All right.
So first of all to recap the red points here are the real salaries.
You know going from zero to I think 1 million for the CEO.
Yes okay.
So these are all the real salaries of this column okay.
And then the blue line is of course
the regression line containing all our predictions.
But the predictions of the linear regression model.
So first of all we can see that indeed the linear
regression model is not well adapted to this data set.
Because indeed, remember that in simple linear regression,
it was well adapted because each time, you know, for each of the values
of the features, well, the prediction was close to the real result.
But here for many position levels, you know, for many values
of the feature, well, the prediction is far from the real result here.
For example, it is quite far from the real salary.
Imagine if we wanted to use that model to predict if someone is saying
the truth, or bluffing about a salary that is contained here.
Well, you know,
we would have offered a way higher salary then we would be supposed to.
So that would not be the best negotiation.
Okay.
So that linear regression model is not well adapted and same here.
It is far from the prediction.
Same here, far from the prediction here. It's okay.
But you know that's only for two points two salaries.
But then here it's super far from the prediction.
And here as well.
So clearly not well adapted.
And that's why I wanted to show you this.
Because now you're going to see
that the polynomial regression results are going to be much better.
And now I'm going to show this to you right away.
So I'm going to close this.
And we're going to visualize the polynomial regression result
efficiently by taking this code.
Because you're going to see that it's going to be almost the same.
So I'm going to scroll down I'll scroll back up to compare.
Create a new code cell facing the here and now.
According to you, what do we have to change here?
Actually something important.
Please press pause on the video now and try to figure out before
I give you the solution,
what you have to replace here in order to visualize the polynomial
regression result.
So please press pause in the video and make that change in order
to make it work for polynomial regression results.