Okay, great.
And now, the last thing that I'm going to do
is maybe to take this code section here. Cut.
And I'm actually going to place it
between the creation of the model and the visualization,
because I like to keep the best for the end and for me, the best part,
the most exciting part is the part where we visualize our results.
And for a second reason is that we know that our problem is
a nonlinear problem, and that therefore we need a nonlinear regressor.
And we're definitely already convinced of that.
That's why we don't need to execute this code section before this one
to convince ourselves that we need indeed, a nonlinear regression model.
So therefore, for the next regression
models, we will make the prediction before visualizing the results.
And that's why I'm putting that here first.
Okay. So I think the template is ready now.
Well maybe we need to change the polynomial here
to generalize the template as much as possible.
So we'll replace polynomial here by.
Well actually let's just put predicting a new result.
All right.
And here we can replace polynomial regression by regression
model.
All right.
And now just to finish this template for those of you who are also interested
in getting a smoother curve in your regression model, results.
Well, there is this trick we can do to increase the resolution.
And we are going to do that right now.
So it's just an optional code section that I'm adding here in this template.
I'm going to copy this because we will have just a few things to change.
And you know, for those of you who really want a very smooth curve
when you visualize the regression model results,
well, you can use the following code.
So the trick is to actually create a new sequence of levels.
That means that hue.
And we are predicting only ten salaries of the ten levels.
Well, what we're going to do now in this section
is that instead of predicting only ten salaries of ten
levels, we're going to predict a lot more than ten levels.
And to do that, we will build a vector of imaginary levels
that will actually be levels from 1 to 10 incremented by 0.1.
So that means I will consider level one, level 1.1, 1.2, 1.3,
up to 9.6, 9.7, 9.8 and 9.9.
So that's what we will create in the sequence.
And therefore here, instead of predicting only ten salaries,
we will predict actually 90 salaries of 90 levels.
So that's the trick.
And to build this sequence it's actually very simple.
We are going to call this sequence x grid.
You know because X grid will replace data set dollar level here and data set here.
And this x grid is going to be defined as
SIC which is a function that builds a sequence.
And so in this function we need to input three parameters.
The lower bound of your sequence.
That's actually mean data set level.
Because by doing this
we're taking the minimum of all the levels in your original data set.
All right then the next parameter is the upper bound of your levels.
That is level ten.
And therefore we do the same with the max here Max
data set dollar level.
All right.
And the third parameter is the step.
So that's where we increase the resolution and make our fitting curve smoother.
Because here we're going to take a step of 0.1.
And therefore 90 levels will be created here from 1 to 10 incremented by 0.1.
All right. So that's actually done.
And now we need to replace data set dollar level here.
That originally took the ten levels of our data set.
So we are replacing that by x grid.
And same here.
We need to replace data set here by a new data frame.
Because you know this new data argument here is expecting a data frame here.
So we cannot replace it directly by x grid here.
Because X grid is not a data frame. It's a sequence.
That is it's a vector.
So what we need to do here is use this little trick.
Again. Don't worry it's quite simple.
We need to use this data frame data dot frame command here.
That will actually create a data frame.
And in parentheses we're going to specify that we want to create a data frame
of new levels.
So I'm taking the variable level here and then equals.
And that's where you put x grid.
Because you know by doing this data frame level equals x grid.
We are just creating a new column of levels
containing all the levels in this sequence X grid here of levels.
And that's it.
This new code section is ready to plot.
Your regression model results in higher resolution
and actually we're going to specify here that it's for higher resolution
and smoother curve.
All right. And that's actually ready.
So you can try it on either
you know your polynomial regression model that we made in this section.
Or you can use it on the future
nonlinear regression models that we're about to build.
And you will see the difference between these two.
But then if you want a more simple code, you can use this one.
Or if you have for example, a data set with 100 observations incremented by one,
then this is the code you need to execute, because then you wouldn't need a
no point one step to build your different points of your fitting curve.
All right. So now the template is ready.
We are actually ready to use it
for the next nonlinear regression models that we're about to build.
We will do that in the next sections.
And you're going to see how it will be so efficient at building this.