Hello my friends.
All right.
So how did you do with the little exercise here?
Predicting the test set results.
So, based on what we've just done in the previous tutorial,
you know, when training the simple linear regression model on the training set,
and also based on the hint I gave you, you know, this predict method?
Well, you should have been able to crack this.
All right.
So now we're going to implement
the solution together starting by creating this new code cell.
All right.
So first let's just explain what we want to do here.
We want to predict the result of the observations in the test set.
And so let me show you once again the data set.
So that's the whole data set containing the 30 observations.
And we actually splitted this data set into the training set and the test set.
The test size was chosen to be 0.2, meaning that
20% of all these observations went into the test set.
So 20% of 30 is actually six.
So let's say just to simplify the explanation
that the observations of the test set are the last six ones.
You know, 123456.
So let's say all of these observations went into the test set.
Well, what we want to do now is predict for each of these observations,
meaning for each of these employees the salary.
Right.
So what we're going to input in that predict method is exactly
the number of years of experience for each of these six employees.
And our model will predict the salaries.
So the salaries that we see here, you know, the last six ones
are the exact salaries. You know the truth.
We call it the ground truth.
And when calling the predict method on these
six numbers of years of experience, we will get six predicted salaries.
And so what?
We'll want to do then will be to compare the predicted
salaries to these real six salaries okay.
And we will do that in the last steps of this implementation.
When visualizing not only the test results but also the training
set results you're going to see, everything will be super clear.
All right so let's do this.
Let's get the test results by.
First.
You know, in order to call a method we first need to call the object itself
which is regressor.
So that was the first step you had to do here.
Then from our object we add a dot here.
And we call the function we want.
Oh wow. It's funny.
The Google collab actually guessed what I was about to call.
That's I never noticed that. But anyway, yeah, that's perfect.
We want to use the predict method.
Of course that was the hint.
And this predict method, you know as any function expects some arguments.
And so now according to you what does we have to input in this predict method.
Well that's simple.
Once again you know we want to enter the features
meaning numbers of years of experience and not the salaries.
That was just for the training set.
Here we only need the numbers of experience,
because from the numbers of experience we want to predict, the salaries
and the numbers of experience are exactly contained in X test.
Right.
Because we want the numbers of experience of the test set.
And so the only thing we had to input here is X test.
And there you go. That was the solution.
Okay. So as you can see once again very easy.
That's the beauty of the libraries.
You can just do anything you want in usually one or 2 or 3 lines of code.
And here we just had to call the predict method to make some predictions
from a model that is of course already trained on the training set.
All right.
Now, because we were going to visualize then the training set results
in a test result.
I'm actually going to put
all these predictions because this returns actually a vector of predictions.
You know, a vector
containing the predicted salaries of the employees in the test set.
So I would like to put all these predicted salaries in a vector,
therefore in a new variable.
And therefore here I'm creating this new variable which I'm calling y pred.
You know, as opposed to y test which contains the real salary.
So make sure to understand why test here contains the real salaries
and why it here contains the predicted salaries.
And now in the next steps we're going to compare white bread to
white test and also will compare Y train to the predicted salaries
in the training set.
And the last two steps of this implementation
visualizing the training set results and visualizing the test results.
We will get amazing graphs, super clear super simple to understand,
and we will clearly see how well our model was trained with this visualization,
and how well our model was able
to predict new observations with this visualization.
So let's do this in the next tutorial.
And until then, enjoy machine learning.