All right.
So now, my friends, we're going to rerun all this, right?
Because we're basically done.
And so to run all this again we're going to first upload
the data set because it is not yet uploaded in the notebook.
So upload and then make sure to find
your whole machine learning is that folder containing all the codes and data sets.
So then we're going to go inside.
Then we're going to go to part three classification.
And then K nearest neighbors Kiernan and then Python.
And then we select our social network add data set click open.
Now it's going to be uploaded on the notebook.
Perfect. There we go.
Now we can run everything.
And to do this well we're going to click runtime here.
And then simply run and let's just start from here okay.
Great.
k nearest neighbors classifier was created and trained properly.
And at the end.
So all the predictions are generated.
Again we can actually have a look at them.
And wow, we seem to have some great predictions that remember on the test set.
So all this is correct.
Here we have an incorrect prediction, meaning that the K and then predicted
this particular customer
to buy the CV, whereas in reality that customer didn't buy the SUV.
Then all this is correct or correct?
All correct.
It seems really good.
Here we have another incorrect prediction, this time the opposite one.
Our model predicted
that this particular customer didn't buy the SUV, whereas in reality that customer.
But the SUV.
All right. Correct. All correct. All correct.
So pretty good.
Wow I think we actually have very, very few incorrect prediction.
Let's actually check it out right now okay. No.
So I didn't see it properly.
But we actually have in total four plus three incorrect predictions.
That's really really good.
That's better than the logistic regression model.
Remember we had actually an accuracy of the test set
of 89%.
So here clearly the K-nearest neighbors did
better than the logistic regression model.
And you will perfectly understand why when I show you the visualization.
So it's actually here.
All right.
So four plus three equals seven incorrect predictions.
Then 64 correct predictions of the class zero
meaning 64 correct predictions that the customer doesn't buy the SUV.
And 29 correct predictions of the class one
meaning 29 correct predictions that the customer buys the SUV.
And then we have indeed
four incorrect predictions of the class one, meaning four incorrect predictions.
The customer buys the SUV and three incorrect predictions of the class zero,
meaning three incorrect predictions that the customer doesn't buy the SUV.
So very, very good.
And now, as you can see, it is still executing the cell that plots
that 2D array.
You know, showing all the prediction regions
and prediction boundary of the canine model
first on the training set and then on the test set.
And the reason why it is taking some time here to execute.
Oh, there we go.
We have perfect timing is simply because, you know, the K and end
model is actually very compute intensive.
You know, there are a lot of computations when running the canine model.
And that's why it took some time.
And so now let's interpret the results.
So remember with the logistic regression
classifier the prediction boundary was a straight line.
And that's because the logistic regression model is a linear classifier.
We'll actually see another type of linear classifier in this part.
But remember for linear classifiers the prediction boundary
or prediction curve for classification is a straight line.
And in three dimensions it's a straight plan.
And then in dimension it's a straight hyperplane.
And so here we had a straight line which therefore
resulted in having a lot of incorrect predictions.
Because as we can see there are a lot of green points here.
You know, green customers who but the SUV in reality that fell
in the red region where we predict indeed that the customers don't buy the SUV.
And same for these ones here.
You know, here we have a lot of customers who in reality but the SUV.
But we're predicting the two because they fall in the red region.
And so what we were hoping for is to build a new classifier
for which the decision boundary, you know, separating the two prediction regions
does something like this, you know, would not be a straight line,
but some kind of a curve catching all the red points here
without catching those green points here and here.
Okay, so that's what we were hoping for.
And well, that's exactly what we got here.
Thanks to our Kiernan model.
We don't get a smooth curve, but we get actually some kind of a curve
that indeed catches all the red points here
without catching the green points and leaving those green points
and these ones inside the green region where they should end up right.
And of course, here we have some green points that were super hard to catch
because they are stuck in the middle of all those red points here.
So that's fine.
And anyway, in machine learning we want to avoid overfitting.
You know, when we have some two perfect predictions on the training set
and therefore probably resulting in having bad performance, bad predictions
on the test set and well, speaking of the test set,
let's see how our key and did it should be fine now.
Yes, it is executed and once again we get excellent results.
Right.
Because same the key and prediction curve or prediction boundary
or even decision boundary catches all the right customers.
You know, the red customers who didn't buy in reality
the SUV therefore leaving the green customers who
but in reality the SUV in the right prediction region, the green region.
All right. So that's already much better.
And indeed we increased the accuracy of the test set by 4%.
And now the question is can we do even better than this.
Well, that's exactly what we're going to find out
in the next practical activities to discover the big winner.
And until then enjoy machine learning.