All right, let's do this.
Let's predict the test set results.
So as I said in the previous tutorial, we're going to display two vectors.
First one being the vector of the real profits in the test set,
and the second one being the vector of the predicted profits in the same test set.
And we're going to compare next to each other
to see if our predictions are close to the real results.
All right, let's do this.
Let's start by creating a new code cell.
So the first thing I asked you to do was to indeed get that vector of predictions.
So first, since we want to get a vector, I'm going to introduce a new variable,
which I'm going to call as usual y pred.
So that's going to be the vector of the predicted profits in the test set.
And now how do we get our predictions.
Well you know the solution.
It's actually exactly the same as with simple linear regression.
We first need to take our regressor object.
You know our multiple linear regression model from which
we're going to call that predict method.
And of course in this method we have to input the features of the test set.
You know exactly these ones not including the prophet of course.
These are all the features with first the encoded variables
for the state, then the R&D spend and the administration spend.
And the marketing spend.
All right.
So these are all the features which we need to input in our predict
method here in order to predict the profits.
So let's do this X test.
And there you go.
Now we get our vector of predicted profits.
Perfect. And now the next step.
The thing that I'm going to do
is I'm going to call numpy, which has a shortcut NP from which I'm
going to call one of its function which is set underscore print options.
And now in the parentheses I'm just going to enter
precision equals to.
All right.
And this will display any numerical value with only two decimals after comma.
All right.
So this will be much more beautiful
to visualize and mostly much easier to visualize.
Okay. Good.
And now final step.
This is a step where we're going to display the two vectors
of the real profits and of the predicted profits together next to each other.
And to do this well we're going to use, you know, a classic trick with numpy.
Concatenate.
Concatenate is a function of numpy that allows to concatenate
either vertically or horizontally two vectors or even arrays.
And so now we're going to use the concatenate function to concatenate
vertically are two vectors of the real profits and the predicted profits.
All right so let's do this. Just follow me.
I will explain everything as I'm coding.
So first we're simply going to start with a print.
You know because we want to print that concatenation of the two vectors.
Then here we go.
We're going to call that concatenate function by numpy from which there we go.
We call the concatenate function perfect parentheses.
And now be careful because this is always a bit confusing.
The concatenate function by numpy actually expects as a first argument.
Check the cell here, the couple of arrays you want to concatenate
or you know, vectors.
So actually all the description is here.
You know A1, a2 is a sequence of arrays you want to concatenate.
And that must have the same shape.
Well that's perfect for us because of course our vector of predicted profits
and the vector of real profits have exactly the same shape, meaning
they are one dimensional vector containing the same number of profits.
Okay, so that's good.
But these vectors that we want to concatenate have to be
in, you know, some parentheses.
And these are actually the first argument.
You know, this double of arrays of vectors is the first argument
input in parentheses.
So here I'm going to add new parentheses.
All right. This is the first argument.
And what is going to be inside this parentheses.
Well of course are two vectors
the vector of predicted profits and the vector of real profits.
All right.
So let's first add the vector of predicted profit.
This is of course what pred.
And now because we want to display them vertically
and not horizontally remember that.
You know actually I can show this to you in data preprocessing tools.
We actually printed Y at some point.
There we go.
You know, remember when we print the dependent
variable vector, since it is vector it is displayed horizontally.
I actually prefer to display,
you know, our two vectors of predictions in real profit vertically.
So now I'm going to add another trick to put that vertically.
You know, to convert that from being horizontal to vertical.
And the trick to do that is just add dot reshape.
Reshape is an attribute function that allows
to, you know, reshape your vectors or arrays.
And in order to reshape a vector from being horizontal to vertical,
well, we just need to add as input of this function.
First, the number of elements in y print.
And that's actually so far the number of columns
because you know it is horizontal.
And to get that number we can simply use the
Len function, which returns the length of a vector.
And therefore here I'm going to input y Brett okay.
So this is the first element of the reshape function.
And the second one is just one.
All right.
So what does it mean.
That means that you want to reshape your y vector into an array.
Having Len y red rows.
Meaning you know that the number of rows will be equal to the number of strips.
And then just one column.
All right.
That's what it means.
So it's good that you know this reshape trick.
Now you know how to reshape your vectors.
And you will see that it is actually going to be much nicer.