So we're
going to open our ipynb file or Python file.
Let's open this right now. And there we go.
So I remind that this notebook is in read only mode.
And since we, as usual, want to re-implement this from scratch,
we're going to go to file here to create a copy by saving a copy in drive.
And as you see it is creating a copy
in which we will be able to re-implement the whole model from scratch.
And there we go.
All right.
So now as usual, we're going to delete all the code cells
so that we can re-implement this from scratch.
Make sure to only delete the code cells and not the text cells.
So we can see the structure.
And lastly this one perfect.
All right.
So this is the whole structure of this implementation.
Let's have a look.
So we're going to start by importing the libraries then importing the data set.
Then as I told you we're going to skip this step
where we split the data
set into the training set and the test
set simply because we want to leverage the maximum data in order to make our future
prediction of the salary for the position level between 6 and 7.
So we skip this step and then we move on directly to first.
Actually the training of the linear regression model on the whole data set.
And that's for the simple reason that we want to compare the two
models, linear regression and polynomial regression.
Because I want to show you that indeed, a polynomial regression
model will be much more adapted to this data set.
So in the end, we will actually, as you can see, predict the salary of the
position level between 6 and 5 with linear regression and polynomial regression.
And you will see that we will get a much better result with polynomial regression.
Okay.
So after training the linear regression model on the whole data set,
we will train the polynomial regression model on the whole data set as well.
Then we will visualize the linear regression
results on the whole data set again.
And then the polynomial regression result.
And finally we will make our last two predictions.
Predicting a new result with linear regression
and predicting a new result with polynomial regression.
And at the same time you will learn how to make a single prediction.
You know, because what we've done so far, you know, when making predictions,
was to input the whole test set features, but you actually still don't know
exactly how to predict the result of a single observation.
And that's exactly in this practical activity that you will learn it.
Okay. So that will be a good new skill to know.
And I will of course ask you to try to do it on your own before we do it together.
And so there you go.
That's the whole structure.
And now we're ready to start.
And we're going to tackle this semi data preprocessing phase.
And Fleshlight starting by importing the libraries
and thanks to our data preprocessing template.
So I'm copying this here pasting that right here in the new code cell.
Then we're going to import the data set using still our data
preprocessing template.
Because indeed we will have only one thing to change
which is of course the name of our data set.
No, actually my mistake.
We will have two things to change.
And I will explain why right away.
So first let's change that obvious thing, which is the name of the data set.
So let's see the name of the data set again position salaries.
All right.
So let's do this I'm going to replace data here by position salaries. Oh
great.
And now the second thing I wanted to change
is of course the matrix of features X.
Because remember that this automatically takes all the columns except the last one.
But actually here you know these two columns are redundant.
It's like we already did
the label encoding, you know, to encode each of these positions
into numerical integers going from 1 to 10.
But I wanted to leave that column because it's pretty nice to see the names
of the different positions, you know, from business analyst to CEO.
So we actually don't want to include this column.
And therefore
we will start to get the column from the second index, which is index one.
Right. Because indexes in Python start from zero.
So there you go.
We're only going to take that column.
And to do so well we're going to replace that
empty lower bound which means the first index by index one
so that it will indeed take all the columns from the second one,
you know, of index one up to the last one, except the last one, and therefore
it will take all the columns from this one except this one, and therefore
just this one. See, just a simple trick.
All right. So now we're all good.
This will still take the last column, the dependent variable vector
containing all the salaries.
So we're all good.
And we can move on now to the next step which will be to train
the linear regression model on the whole data set.
Great.
So would you like to execute this now?
Yes. Maybe. Let's do it now so that it's done.
So let's click this folder here to be able to upload the file.
Right now it is connecting to a runtime to enable file browsing.
And in a second.
Yet there we go.
We should be able to upload the data set.
All right.
So we're going to go to our machine learning.
It is that folder I always put it on my desktop.
Then part two regression then section six polynomial regression.
Then Python.
And there you go.
Let's get and upload our position salaries data set.
That's all good.
Now we have it.
And now we can run these first two cells.
First importing the libraries
okay done.
And now importing the data set and done as well.
And now we can move on to the next step training the linear regression model
on the whole data set.
So try to do it on your own because you now know how to implement
the linear regression model.
So I trust you will smash this. There is no trap.
And this will be a good way to practice again.
So as soon as you're ready
well let's move on together to the next tutorial to build that
first linear regression model together and then the polynomial regression model.
And until then, enjoy machine learning.