Perfect.
The next step is to, of course, create an instance of this class,
which will be an object representing exactly that naive base model.
And so there we go.
We're going to call this as usual classifier
in order to be coherent with the next sections
of this implementation, and mostly so that we don't have to change anything.
Right.
Because then we call this
classifier variable to predict the results and visualize the result.
So there we go classifier here.
And then and then we're going to call this Gaussian NB class
in order to create indeed this Naive Bayes model.
Okay. Perfect.
And now you know how to finish this.
We need to take our classifier again, from which we're going to call the fit
method, which will train this classifier on the training set
composed of indeed x train and Y train.
Right?
I hope you did it even faster than me,
because indeed, this is exactly the same as before.
And now you are also independent
and know how to find the information you need in the API.
Okay, great. So once again there we go.
That implementation is over and we ready to get the final result.
And mostly we're ready to find out if we can beat
the record accuracy you know if 93%.
So I can't wait to see. So let's do it right now.
Let's click this folder button to upload a data set.
Right.
We have to do it in order to train.
Indeed that Naive Bayes model on the training set.
Right now your notebook is connecting to a runtime to enable file browsing.
And once again, in this second we should get the up button.
There we go. So we're going to click it.
And here we are in the kernel SVM folder.
So let me show you the path once again please.
Fine your whole machinery.
It is that folder which you could download in the previous tutorial if not already.
And then inside we're going to go to port three classification.
Then section 18.
We're making good progress here.
Naive Bayes then Python and then social network
ads dot csv okay we press okay.
Here we have the data set. All good.
And now now we can run everything in order to get indeed our new result.
So let's do this run all.
And now all the cells are running.
And especially this one. There we go.
We now have our Gaussian Naive Bayes model.
And well let's see the results one by one starting with this one.
So that's the prediction of a single result.
You know that first customer of the test
set of age 30 and estimated salary $87,000.
And remember in the white says the real outcome
was zero meaning that this customer didn't buy the SUV.
And that's the prediction, which is indeed the correct prediction.
And then when predicting the test results, well,
once again we see that we have a lot of correct predictions.
All this is correct.
This is our first incorrect prediction.
Another one here and then another one here.
All correct. I'll correct another one here.
Oh I'm not sure we're going to beat actually that accuracy
we seem to have more than seven incorrect predictions at first I'm not sure.
But let's see, let's see.
Well, that's exactly what we're about to find out right now.
So are you ready?
The question is, will we beat the accuracy of 93%?
Which was the best accuracy resulting from both Kilian and any kernel SVM.
And so let's see what we get with Naive Bayes.
And no, unfortunately we don't beat the record.
Indeed, the accuracy we get with that Naive Bayes model is 90%,
which beats indeed logistic regression, but does equally the same
as the classic SVM model with a linear kernel.
All right, but still, I think we will get nice visualization results.
That's the code cell where we visualize the training set results.
And well, this time we got the results pretty fast.
You can see that the cell is already executed.
So let's see I can show you that indeed the Naive Bayes
curve is pretty nice right?
It is a nice smooth curve right?
That catches well indeed these
green customers here, you know, the ones who in reality.
But the SUV in the right green region but unfortunately you know it's separated
the two classes.
You know
with these two prediction regions a bit large, you know, not very precisely.
And that's why we don't get an accuracy that is higher than 93%.
But still, you know, we made a progress with respect to logistic regression
because indeed remember that for logistic regression
these green customers here could not be well classified.
Right. Because of the straight line.
They fall in the red region.
And here in our Naive Bayes implementation, well these green customers
fall in the right region. So at least it corrected that.
But since here there is kind of a large margin, well these green customers
which were correctly classified with the kernel SVM,
if you remember right, these are the training set results.
Right. So I'm talking about these ones here.
They are correctly classified except these two and the third one.
But clearly with Naive Bayes.
Well they fall into the wrong region okay.
But anyway, at least you see the prediction curve of the Naive Bayes model.
And mostly you see that Naive Bayes model is clearly a nonlinear classifier.
And, you know, in some other situations, because the naive Bayes is causing less
overfitting, well, in some situations it will do better than your other models.
That's why it's always very important to try all of them.
And remember, at the end of this part, I will actually deploy
all our models with new simplified code templates for each model.
You know, without all the prints and everything,
in order to deploy them in a flashlight so that we can quickly figure out
what is the best classification model for any data set.
You know, regardless of the number of features.