Hello and welcome to this art tutorial.
And now we are ready to move on to the next step,
which is to fit our polynomial model to the data set.
However, I would like to show you how the polynomial regression
model is a much more powerful model for our situation,
and the best way to show you this is to actually compare it to a baseline model,
like a reference based model, which will be our linear regression model.
That's why in this tutorial we will build two models
the linear regression model and the polynomial regression model.
And then we will compare the results.
We will compare the graphic results and also the predictions.
So you'll be convinced that the polynomial regression model
is a much more appropriate model for this problem.
And the main reason for that is that our problem is a nonlinear problem.
Okay.
So let's start by building this linear model.
It's going to be very quick because we actually already did this.
So you know we start by creating our regressor that this time
we're not going to call it regressor
because we will build two regressors the linear one and the polynomial one.
So we will call it Lin rank.
Here we go.
And then you know later we will call our polynomial regressor poly rank.
So Lin rank equals.
And then remember we have to use the LM formula.
And so we need to add some parentheses here.
And then let's remind ourselves what we need to input
by pressing F1 here to have a look at the arguments okay.
So remember the first argument is formula.
So the formula is very simply the salary.
That is our dependent variable
tilde.
So I just pressed alt n and then a dot here
to take all the independent variables.
But actually there is only one independent variable.
So the dot here is strictly equivalent as just writing level okay.
So perfect for the first argument.
And then what is the second argument. It's data.
So data okay.
So let's add this argument data equals and now let's see okay.
So in the linear regression section we actually used the training
set here as the data argument to train our linear regression model.
But as we explained
before here we did not split the data set into the training set or the test set.
So we are simply going to train our model on the whole data set itself,
because it's a small data set anyway, and we want to have
the most accurate prediction.
So here simply we will just input data set.
All right.
And our linear regression model is ready.
We are actually ready to build it.
So let's just do it.
Let's build our linear regression model
I'm pressing Command and Control plus enter to execute.
All right linear regression made.
We can have a quick look at the summary here.
Summary linear lag.
So I'm typing this in the console and pressing enter.
And here are the statistical results of the model.
We're doing this on R because as you can see it's really easy on Python.
We would have needed to import a class create an object here.
It's really easy.
So we can have a look and we can see that
the level has two stars here for the level of significance
and is actually not a bad predictor of the salary.
But wait for the polynomial model
to see how it's going to be much better than linear regression.
Okay, so now let's move on to the next level.
That is the better model polynomial regression.
And let's build it okay.
So as I mentioned we are going to call this regressor poly underscore rank.
All right this way.
And you know since the polynomial regression model
is actually a multiple linear regression model in which the independent variables
are actually the polynomial features of one independent
variables, as Carol explained in the intuition tutorial.
Well, we are going to use again the alarm function as we did for linear regression.
So here I'm just going to start by taking my lm function.
Add the parenthesis and we're going to input our two arguments
formula equals salary
tilde of n and then this dot here.
But don't worry we'll actually represent something else.
So so far I'm just putting the dot and you'll understand
what's going to happen next which will make our polynomial regression
built correctly.
So then comma and then we add our second argument
which is still going to be the data equals data set.
Because we're going to train
our polynomial regression model on the whole data set okay.
So now you must be telling yourself wait.
But this is exactly the same as linear regression.
Well that's true.
And that's why we need to add a little something here
to make this model a polynomial regression model.