All right.
So that's the results of the training set.
These are quite good results.
But that's because we trained our linear regression models on the training set.
And now let's see how our simple linear regression model can predict
new observations.
That is new observations of the test set.
So I'm going to close that okay.
And now let's do the same for the test sets to see if our simple linear
regression can make some good predictions on new observations.
So the test set observations on which our model wasn't built.
So as usual we want to be efficient.
And so we're going to copy all this
copy and paste it here.
Okay.
So let's replace all the training set here
by to set okay
here as well.
Training set to set.
That's the test results okay.
So now we must be careful with something.
Let's see if we have to replace all the training set.
So in the first component of ggplot that is when we plot
all the observation points.
The real observations
here we have training set years experience and training set salary.
In your opinion do we need to change training set here by test set?
Yes of course.
Because this time we want to have the observation points of the test set.
So we want to
take the years experience here of the test set observations
and the salaries of the test set observations.
And here we will replace training set by test set okay.
But now in geom line.
So that is the component that builds a regression line.
Do we need to replace training set by test set here.
You know training set here and training set here.
Do we need to replace those two training sets by test set.
Well the answer is actually of course no
because our regressor is already trained on the training set.
So whether we keep here the training set or replaced by test set,
we will obtain the same simple linear regression line.
Indeed, if we replaced here training set by test set,
we would just build some new points of this same regression line
corresponding to the new predictions of the test set observation points.
Because when we trained our simple linear regressor on the training set,
we obtained one unique model equation, which is the simple linear equation
itself.
And therefore,
whether we build the regression line here by predicting the training set points
or the test set points.
Well, since this predictions result from the same unique
simple linear equation, we will get the same regression line.
Okay, now.
So that means that now we're ready okay.
To set to set test it here and training set here.
We're all good.
We are ready to plot the test set results
to find out how our simple linear
regression behaves on new observations.
So let's do this. Press Command and control.
Plus enter to execute.
And here we go.
So as you can see as I was telling you if we go back to the training set here,
you can see that only the red points change you see.
And the blue regression line doesn't change.
You see, it's the same here.
Only the red points change.
So here that's the training set observation points
with the model built on the training set.
And here that's the test set observations with the same regression line
builds on the training set okay.
So now let's zoom on the test set plots and give some interpretation
okay.
So the test set results are actually not bad.
We can see that we have some very good predictions here.
For example for this employee this employee this employee
and this one as well.
Because as you can see the real value is closed to the prediction
which is on the blue regression line.
So since these are new observations on which our simple linear regression
model didn't learn any correlation, that's actually quite a good job
to find, you know, predictions so close to the real value.
And of course, there are some predictions that are further from the real value.
But that's because there is not, 100%
linear dependency between the salary and the years of experience.
But for sure there is a certain linear dependency.
All right.
So thank you for watching this tutorial about simple linear regression.
In the next section, we will find out about a new type of linear regression,
which is going to be the multiple linear regression, meaning that instead
of having only one independent variable, we'll have several independent variables
that will predict a single dependent variable.
So there will be a new business problem, and I can't wait
to solve it with you using multiple linear regression.
I'll see you in the next section.
And until then, enjoy machine learning.