Hello, my friends.
All right, let's see if you got this right.
Again, predicting the test. Results.
And displaying the vector. Of the. Predictions next.
To the vector of the real. Results, meaning the real.
Purchase. Decisions.
And I really want you to.
Juggle with all your toolkits, you know,
whether it is the data preprocessing toolkit or your other.
Machine learning models, where you have indeed.
Several tools inside.
Because indeed, now.
The tool we would like to use is that. You know.
A little piece of code
that allows to display the two vectors of predicted results.
And real. Results.
So what I expected you to do, you know, to.
Be the most efficient as you can.
Was to go to part two regression.
And then into the multiple linear regression folder and then open this
multiple linear regression implementation, which indeed contains inside.
So I already opened it.
That tool allowing to display the two vectors
of predicted results and real results.
I'm talking, of course, about this tool. Right.
We implemented it many times.
That's why I didn't want to do it again here in R.
Just a. Regression implementation.
Plus I.
Really want to train you and incentivize.
You to.
Be the most efficient as you can
by juggling between your different models implementations.
And so.
If you did this, if you had the reflex to grab that tool right here.
In multiple linear regression or many other models
where we implemented that, well congratulations.
You did amazing.
All right. So here we're going to take this.
And of.
Course if you.
Reimplemented it. Yourself that's also. Amazing.
Especially if you managed to be more efficient than how we were.
Able to be.
All right.
Because what we only have to do here is to copy this little piece of code.
You know that tool. And.
Paste it.
In a new.
Code cell here to predict the test results.
Because indeed we have. All the.
Same names here. For the vector of.
Predictions y.
Pred, which will be the result of the.
Predict method.
Applied to test.
Set and called of course from our not.
Regressor object but classifier object.
There we go.
So that's the. First change you had to make.
And then. Well. Since this time, you know.
Our predicted purchase.
Decisions and the real purchase decisions are.
Either zero. One.
Well we don't need to add anything here. To.
You know, forced a number of decimals after the comma to.
Be only two.
Right here we're. Only dealing with integers.
So we can remove this.
We don't need this.
And then final question here.
Do we have. To change anything.
Well absolutely. Not.
And that's what I mean by, you know, grabbing a tool and applying it
on your new model by only having to change 1 or 2 things.
Here we only changed the name of the model type, you know, from.
Regressor to classifier.
Okay. So let's check it out.
Let's see if it works.
Let's press play here.
And indeed.
We get the two vector is. Next.
To each other with.
First on the left.
Your vector of. Predictions.
You know of the. Predicted purchase. Decisions for.
All the.
Customers of of. Course the test set right.
This was applied to excess here.
So that's all the customers of the test set.
And on the right in the second column you.
Have the real purchased decisions.
And so here what's interesting to see is to compare.
The predicted purchase.
Decisions to the real ones.
For all. The customers in the test. Set.
All right.
So let's see for the first.
Customer of the test set,
you know remember of age 30 and estimated salary 87,000.
Dollars.
Well the prediction is no.
This customer didn't buy the new SUV.
And the real result is indeed no.
In reality, that. Customer didn't buy the new.
SUV. Good. Same for the second customer.
That customer was predicted
not to buy that new SUV, and indeed it did not buy the new SUV.
Third customer this time the third customer actually.
Bought that new SUV.
And our model predicted that indeed, this new customer bought it.
Well, it's funny, we actually have a lot of a correct predictions.
That's amazing. Right?
All this so far is correct. This is correct.
And here.
We go. We have our first. Incorrect prediction.
Here. Our logistic. Regression model.
Predicted that this particular.
Customer didn't buy the.
SUV because we have a prediction of zero here.
But in reality that.
Customer bought that new amazing. SUV. Okay.
Because the real result here is a one.
Then here. Is correct. Correct. And here we go.
Another incorrect prediction
where our model predicted again that this customer didn't buy the.
SUV, whereas in reality.
That customer. But the new SUV.
All right. And you see so.
That looks really really good actually we will get a.
Very nice confusion matrix.
I will explain very soon what it is.
And mostly a.
Very good accuracy because the accuracy.
In the test set.
Of course.
Is simply the number of correct predictions.
Divided by the.
Total number of observations in the test set.
And this. Is exactly what we're about to get.
In the test set.
We will not only get the confusion matrix showing.
So there. You go. I'm about to explain what it is.
The confusion matrix. Will show us exactly.
The number of correct predictions and the number of incorrect predictions.
For the two cases where the real result was zero.
Or one to.
Basically, we will have a nice matrix
showing how many mistakes and correct predictions our model made.
And of course inside the same new.
Step or code cell.
We will compute.
The accuracy and we will see what is the.
Percentage of correct predictions are moral made on the test. Set.
So should I ask you to try to do it.
On your own? Well, yes. Why not? Because, you know, you.
Just have to go to the API of scikit.
Learn and. Figure out.
How to make that confusion matrix and how to compute the.
Accuracy. And now I'll just give you a little hint.
You will.
Have to look.
Into the metrics module from scikit learn.