Hello and welcome to this art tutorial.
In the previous tutorial was a lot of, interesting things to learn about R
and what it can do to provide insightful informations of your model.
And now what we only have to do left is to predict the test results.
As for a simple linear regression, it will be very quick.
We will just need one line for this and it's going to be
y pred.
I'm introducing the vector of predictions here Y pred.
And then I'm going to use the predict function.
And then the predict function I will just use two arguments.
One is the regressor.
You have to specify with which
regressor you want to predict your test set results.
And of course it's with our multiple linear
regression regressor that we define here.
And the second argument is new data
which is the set of the new observations.
You want to predict the result you want to predict the profit.
And so of course this new data
is going to be the test set.
Don't worry if so far
we are only making predictions about the test set.
You will see that in the next sections we will be making predictions
of new observations,
which won't be the test set observations, but some single observations.
You will understand why we will do this, and you will see that
the purpose of doing that is actually going to be pretty fun.
So the okay, so that's ready.
The predict function is ready.
It has its two argument the regressor and the new data.
So we're ready to select this and execute.
All right.
And now our widespread vector of predicted results of the test
set is ready.
So what I'm going to do now is to type
Y pred in the console to have a look at it.
Here it is.
So as you can see this contains ten predicted results.
These are the ten predicted profits of the ten observations of the test set.
So for example let's compare the real profits and the predicted profit.
So let's look at our test set here okay.
So let's look at our startups.
Let's look at startup number four.
And startup number four has a $182,000 profit.
And what about the prediction $173,000 profit.
So that's the predicted profit which is not far from the real profit.
So that's pretty good okay.
What about the second one.
166,000 for the real profit and 172,000 for the predicted profit.
Not too bad either.
Then third observation 155 160. Good
146 135.
Not too bad then. Okay.
Then. For example, let's look at the start.
Number 24 started number 24 had a real profit of $108,000,
and our predicted profit is $110,000.
So here we're pretty close. That's an accurate prediction.
Good one okay.
And oh that's even better for the last two ones because here it's 99,000.
Here it's almost 99,000.
And 97 here for the last one and almost 97.
So that's pretty good. That's a good model.
And remember that's the model with all the independent variables.
But as we saw there is only truly significant variable
which was the R&D spend.
And so if we try to recompute the regressor by only putting the R&D
spending dependent variable here, you will see that the predictions
are going to be the same with the same accuracy,
because the R&D spend is the only strong predictor of the profit.
So you can try that yourself.
It could be a good practice.
You can play around with the different independent variables.
So I will let you do it yourself and continue to analyze,
interpret and play around with the multiple linear regression.
That's the end of this tutorial.
I was very happy to teach you how to make multiple linear regression model.
I look forward to seeing you in the next section where we'll be talking
about a new kind of regressor, because this time you're going to see that
it's not a linear regressor, it's going to be a polynomial regressor.
And I can't wait to show you how it can give powerful predictions.
And we are going to use it on a very funny example.
So there will be quite a challenge here.
And just to give you a teasing of what we are going to do,
we are going to make kind of a lying detector.
So I look forward to seeing you in the next section.
And until then, enjoy machine learning.