All right.
So good.
Now we're going to do the same. For the test result.
So I'm just going to copy everything here and paste that in a new.
Code cell right here.
And so now we're going to.
Do the right.
Replacements in this code in order to visualize this I'm not the.
Training set results but the test set results.
And so obviously.
The first thing we need to replace here are the.
Coordinates.
Of the real observations.
Because these are the coordinates of,
you know, the employees in the training set.
And we want the coordinates of the employees. Of the test set.
Therefore here we have to replace obviously X trained by X test.
And then Y train by. Y test.
Okay.
So these are for the real.
Observations with the numbers. Of years of.
Experience and the.
Real salaries of the test set.
And now.
According to you, do we have to replace.
Something here in PLT.
Plot x. Train.
Regressor dot predict x train according to you, do we have to replace.
X train by x. Test.
And the same x trained by x. Test.
Well you know that's kind of a trick question because remember.
That the.
Regression line that.
We get is actually resulting.
From a unique equation.
And therefore the predicted salaries of the test set will be.
On the same regression line as.
The predicted salaries of. The training set.
And that's.
Why here we actually don't have to replace X.
Train by.
Test. Here and here. Okay.
You would actually get the.
Exact same regression line.
Whether you plot the.
Coordinates. Of X train and the predicted.
Salaries of training set.
Or X. Test and the predicted.
Salaries of the test set, you can check.
But that's because the.
Regression line in a simple linear regression model.
Results. From a unique equation.
And we therefore end up with the same regression line.
Okay. So no need to replace anything here.
And finally we.
Will just replace.
Your training set. By test set.
And there you go.
Now we're ready to visualize.
The training set results and the. Test set results.
So let's first. Run the cells we haven't.
Executed before.
So remember we.
Executed up to. The training.
So now we have to execute this one to indeed.
Get the vector y pred of the predicted salaries of the test set.
So there we. Go. We now have y pred.
And so now we're going to.
First execute this to visualize the training set results.
And we're going to obtain.
Now nice 2D plot with. Indeed.
The real salaries. In these red points here.
And of course.
Our beautiful. Regression line containing the.
Predicted salaries.
And we clearly see that this. Regression line was.
Calculated so that.
It comes as.
Close as possible to the real salaries.
And of course, for each of the years of.
Experience here, in order to.
Get the predicted salary, you have to project the.
Year of experience.
To this blue.
Regression line. So, for example.
The predicted salary.
Corresponding to. Eight years. Of experience.
Is about.
You know, 100,000. Dollars per year. Okay.
So that's how it works. And so we can clearly.
See that our predicted salaries are very close to the real salaries.
You know, for most of them.
But that's on the training set.
Remember that's important because our model was.
Actually. Trained. With these observations.
You know. With these years. Of experience and. Salaries.
Now what we would.
Like to observe is if we have.
The same results, you know, the same closeness.
Of the. Regression line to the real.
Salaries in the test set with.
Which the model wasn't trained.
You know, we want to evaluate it on new observations.
And that's exactly what this new graphic will tell us.
Because now we were about. To plot.
This time, the real.
Salaries of the test. Set and the.
Predicted salaries at. The same. Test set.
So there we. Go. Let's run this cell and let's.
See if we're still close to the real salaries.
Even for new observations.
And yes.
Absolutely are predicted salaries, which are of.
Course on the blue line once again are very close indeed to the.
Real salaries.
So our model or a simple linear regression model.
Was able to.
Do a wonderful. Job at predicting.
New observations.
So congratulations.
That's very exciting.
You built. A very successful.
First machine learning model.
However, just remember. That.
The reason why we. Get such a good.
Regression line here.
Is simply because there was a linear.
Relationship in the data set between the features
and the dependent variable of. The data. Set.
In other words. We had a perfectly.
Linear data. Set.
In other. Words, we had a data set.
With linear correlations.
And what I want to make sure you understand is that.
These beautiful results.
Won't happen for any.
Data set, because of course, you'll get to.
Work on data sets with non-linear relationships.
And for these data sets, you will need a non-linear model.
And that's exactly why. In this part.
Two. Regression, we.
Will also study. Some nonlinear models.
Which you will see will be.
Polynomial regression or.
SVR, which will allow you to.
Get amazing.
Results for data.
Sets having non-linear. Relationships.
But for this data set, we clearly had linear relationships.
And that's.
Why, Linear regression model.
Was perfectly. Fine.
But I just. Wanted to highlight this okay.
So congratulations once again, I.
Hope you're very happy and excited to have built your very.
First machine learning model.
Now we're going to increase. The difficulty a bit.
Because in the next section we will build a multiple linear regression
model, meaning that instead of having one feature,
you know only one independent variable.
We will have several of them. And that's. Exactly the.
Difference between simple linear regression and multiple linear regression.
Simple linear regression is when you have only one feature,
and multiple linear regression is when you have several features.
So take a.
Good break now, and as soon as you're.
Back with your energy. Let's implement. Our.
Second machine learning model in the next practical.
Activity after.
Intuition lecture.
And until then, enjoy machine learning.