And this little
something that we're going to add is actually the polynomial features.
The polynomial features are actually some additional independent variables
that are going to be the level squared, the level cubed level
to the fourth level to the fifth up to any degree you want.
These are these additional independent variables.
There are going to compose our new matrix of features in some way,
which will actually be the matrix
on which we will apply a multiple linear regression model,
which will make the whole model a polynomial regression model.
So in short, a polynomial regression model is a multiple linear regression
model that is composed of one independent variable and additional independent
variables that are the polynomial terms of this first independent variable.
Okay, so now that we get this idea, you'll perfectly understand
what we're about to do right now when building our polynomial regression model.
Because what we are going to do is to build this polynomial terms.
And to that extent, what we're simply going to do is to add specifically
a new column here in this data set, which will be the level squared.
So we're going to call this new independent variable level two.
And let's add this new column right now.
So to add a column in a data frame we need to take our data frame.
So its data set.
Here it is.
And then we need to add a dollar sign here.
And then we can add any name here which will create a new column of this name.
And add it into our data set.
So we're going to call this column level two
because we're taking the level squared of our ten levels.
Then we add equals.
And then we actually need to give the formula
of the values in this level two column of our data set.
And this formula is therefore the levels in our data set at the power of two.
So very simply we're going to take
all the levels of our data set by taking our data set.
And same adding this dollar here
to take the level column, which is here, I just have to press enter.
So by doing this I'm taking the level column.
That is all the values of the level column in our data set.
And now I'm going to take the square of all these levels in our data set.
And so to do this very simply I just add hat.
And two that's it that we'll just create a new column
which will contain the squares of our ten levels in our data set.
So let's see right now my data set contains only two columns
level and salary. And if I execute this
here we go.
Now let's have a look at the data set.
As you can see I now have three columns level salary and level two.
And as you can notice the values in the level two column
are the squares of the values in the level column.
Okay.
And now we can build our polynomial regression model.
Because now this dot here not only contains the level column
but also the level two column.
So this will build a multiple linear regression model
where the independent variables are the original independent variable
and the polynomial term of this first independent variable.
And if you want to build a polynomial regression
model with a higher degree, well, you will need to do the same here.
You know, we can copy this line and paste it here.
And just add a level three column that will contain the cubes
of the levels in the original independent variable level of our data set.
And as you can see, it'll be very easy.
I just need to execute this line.
And this will add a level three column in our data set.
And so now this little dot here will be
the original independent variable level, the square values of our levels
in level two and the cube values of our levels in the column level three.
You can add as many powers of levels as you want, but maybe we will stop here.
We will see what is the best polynomial regression for our model.
And so we will see what we'll get with this one.
And now let's actually build the polynomial regression model.
If we select this and execute press Command and Control plus enter to execute
and run our polynomial regression model is created.
Awesome.
So we're going to have a look.
Let's type summary in the console poly rag.
And let's press enter.
And let's see where we get okay.
So now what we can see is that these level two and level three polynomial terms
that we created are actually statistically significant variables.
But actually this table here does not show
the real deal of the polynomial regression model for our problem.
You will be much more convinced
in the next tutorial, we will be visualizing the graphic results,
and you will perfectly understand why our polynomial regression,
which is a non-linear model, will make a much better job at predicting what we want
compared to this linear regression model, because it's a linear model.
So we'll check that in the next tutorial.
And until then, enjoy machine learning.