So let's do this.
Let's close the linear regression results.
And let's start to visualize the polynomial regression results.
And you're going to see now how easy it is to go from the linear
regression results to the polynomial regression results.
Because what we will simply do here is,
you know, select this and paste it here.
And now you will see how we only need to change very few things.
So as usual let's start with the simplest.
Let's replace linear here by polynomial
okay.
And now what do we need to change.
Okay.
So do we need to change something in the June point function.
No of course because we want to keep the same real observations.
So that's okay.
And then do we need to change something in the germline function.
Of course. Yes.
Because here we are predicting the salaries of our
ten levels in our data set according to our linear regression model.
So according to you what do we need to change here.
Very simply.
Well actually we just need to change the regressor in the predict function.
And instead of taking the line drag, which is the linear regressor,
we're going to take the polynomial regressor that we called poly rank.
And that's it.
That's actually all we need to do to visualize
the polynomial regression results.
And you will see that in the next sections it will actually be the same.
We will only need to change the regressor to plot
the new graphic results of our future regressors.
So that's very nice.
We're actually ready right now to visualize the polynomial results.
So let's do this with our waiting.
I'm going to select this and press Command and Control.
Press enter to execute.
And here it is.
As you can see this is not a straight line anymore.
Let's zoom on the graph.
All right.
So as I just mentioned, the first reflex to have as a machine learning
scientists is that, this is not a linear model anymore.
And by the way, congratulations.
You just made your very first non-linear model.
We're going to see plenty of other non-linear models in this course.
But this is your first one.
So congratulations.
So as you can see it's not a straight line.
Now it's a curve.
And we can immediately see that the curve is approaching much better.
All the red observation points.
And especially for the CEO here, the CEO wouldn't get mad
now if we negotiated with him its future salary in a new company,
because now the prediction is much closer to the realization point.
And let's check our employee that is about to be hired and that has a 6.5 level.
Well, 6.5 is around here.
And when we project 6.5 on our polynomial regression
model represented by this blue curve, here we get a predicted salary.
Here I'm projecting the point on the curve back again on the salary axis.
And we get actually a salary that is coming much closer
to the salary mentioned by this future employee, which is around 160 K here.
Well, we don't get the accurate prediction yet
because that's what we were going to do in the next tutorial.
But definitely this model is fitting much better.
The data set.
And now, just for fun,
let's add a new degree to see how this model can still be much improved
and almost passing by all the points very accurately as we add more degrees.
So let's check it out.
Let's close this and let's add a new degree.
So very simply what we're going to do
is add a new degree here by copying this line.
Paste it here.
And we're going to add a new column in our data set level four that will
correspond to our original independent variable level at the power four.
And so therefore here we need to compute it this way
by taking the fourth power of level there.
And now let's execute this line to add the level four column in our data set.
Now you can check to see that it's here level four.
Perfect.
And now let's reselect this to rebuild our new polynomial regression
model with this fourth degree. Now.
So executing a new polynomial regression model created.
And now let's have a look at the results.
So these are the previous results
corresponding to a polynomial regression model with a third degree.
And now let's look at what happens with the fourth degree.
So I'm going to select this and execute.
And here are the polynomial regression results
for a polynomial regression model with a fourth degree okay.
So as you can see we can zoom on it if you want.
As you can see
the line is actually strictly passing by all the red observation points.
And now the CEO would be even happier with the negotiation
or should I say even less furious because the prediction
now is actually almost the same as a real observation point.
That is, the predicted salary is almost the same as the real salary.
Okay, and same for our 6.5 level employee.
When we project this 6.5 level here on the curve and then projected again
on the Y axis, that is the salary axis, we get a value around what he said.
That is 160 K.
And for those of you who are interested
in having a more continuous curve here, like we did in Python,
I will add the code for that job in the R file provided in this section.
You can check it out for fun.
And this is the model we're going to use to get the accurate prediction
of the previous salary of this new employee
that is about to be hired,
and we will compare it to the salary that it pretended
to have in its previous company
and eventually tell our final verdict whether it's truth or bluff.
So I look forward to doing that with you in the next tutorial.
And until then, enjoy machine learning.