All right.
So that's the only thing we want to input here.
Or the rest we're going to keep the default values.
Feel free to read them if you need to learn more.
But that's the main parameter.
That's mostly what we have to select here.
And then remember that we will also add a random state parameter
to make sure that we have the same results displayed in our notebook.
All right. So let's do this.
Criterion equals end quote entropy.
Perfect.
And then the second one random state parameter that we set equal to zero.
Great.
And now final step you know exactly what to do.
We take our classifier.
And from this classifier we call the fit method
to train our decision tree classifier.
On the training set that is composed as is expected by the fit method
of x train and y
train, exactly the same as before.
And now once again, we're done very efficiently
with this implementation, so I can't wait to see the results.
I don't think we will beat the accuracy record, but let's see.
We never know.
So let's click this folder button here.
And then you know right now it is connecting to a runtime to enable
file browsing so that, you know, we can access your files on your machine.
And in a second we should be able to get the upload button.
There we go. As usual upload.
And so that's the right data set.
Let me show you the path again.
That's the whole machinery is that folder.
Please find it on your machine.
And then we're going to go to part three classification.
Then decision tree classification.
Then Python and then social network ads dot CSV.
All right let's press okay.
And now here we go.
We are ready to run all the cells by clicking this runtime button.
And then run oh all right.
And now it is training the decision tree classification model.
Here we go.
We have it now you know with all the default values of the parameters
except criterion which we set equal to entropy.
Then what about that new result. Great.
We got the right prediction.
Remember that customer of age 30 and estimated salary $87,000 didn't buy.
In reality, the end was predicted not to buy it either.
So perfect.
Then when predicting the test results, we indeed get a lot of good predictions
except some incorrect ones here, for example.
And then, well, it looks actually pretty good.
Maybe, you know we will be the accuracy.
That's another one. All right. Another one.
And okay let's see okay.
Because you know there's actually also when you scroll up some more prediction.
But let's see I'm very curious actually.
Maybe I spoke too fast.
We're about to find out right now with the confusion matrix.
Are you ready?
The accuracy of the decision tree classification model
is 91%. Wow.
Okay, so it's actually in the podium, you know, right after K and N
and a kernel SVM which got the best accuracy of 93%. Wow.
So that's really good.
Actually this is really a good sign for Random Forest because random forest
is basically a team of decision trees making the predictions.
And you know how team spirit always improves the results.
So we might have a chance to beat the record accuracy with Random Forest.
So that's pretty exciting.
And now when visualizing the training set results which we already got,
no, the execution was not too long.
Let's see what it looks like.
Wow. Okay, so that's pretty different as before.
And no wonder why it got a pretty good accuracy
because indeed it
looks like it was able to catch, you know, the little observation points
that were really hard to catch by either a straight line, you know,
with linear classifiers or a nice curve like with kernel SVM or Naive Bayes.
Here we actually splitted this whole grid into smaller subgrid.
And that's because, you know, we have all these splits
in the decision tree classification algorithm.
So no wonder why we get all these subgrid and therefore we get separate
prediction regions. It's really interesting.
That captures very well the observation points.
So it catches all the red customers here who didn't buy in reality the SUV.
It catches also all these green customers who but in reality the SUV
and it catches you know these very hard to catch customers here
by creating these sub grids of the grid with the right predicted regions.
So you see how it got that good accuracy.
It really tried to catch everything, even for example, these green points
that were cut among all these red points okay.
These red customers okay.
But let's be careful.
The training set, you know, on which the model was trained.
Let's see what happens with the test set.
And we already know that we will get good results
because we already know that the accuracy on the test set is 90%.
But still, let's see what we get
with new observations on which the model wasn't trained.
All right.
This is what we get.
And actually here we see things more clearly.
This is the prediction region you know which funnily was a good fit
for the training set. But here it is not catching anything.
You know, neither
red customers or green customers here seem to be two incorrect predictions.
You know, because they fall in the green region.
then here
that's all good, you know, that's all the customers of small age
and small estimated salary,
which therefore won't be likely to buy the SUV as it is the case here.
And then all these green points are correctly predicted.
This one is incorrectly predicted.
So indeed we have our ten incorrect predictions in all this.
But there you go.
You know,
if I didn't see the accuracy first,
I would be afraid that we have some overfitting here.
But no, it doesn't seem to be the case.
Even with new observations of the test set.
You know, we get great predictions.
But now what I really want to see
is the final accuracy of our final classification model.
Let's find out about this in next practical activity.
And until then, enjoy machine learning.