Hello my friends, and welcome
to this new practical activity for Decision Tree Classification.
And now please follow me into part three classification.
And to implement this time the decision tree classification model.
And as usual we're going to start with Python.
This Python folder contains two files.
The implementation of the decision tree classification model in ipynb format,
and the same data set social network at the CSV,
which contains information of 400 customers of a car dealership
which just released a brand new luxury SUV.
And the strategic team gathered this data to understand
which customers buy the most SUV in order
to target them with ads that will be posted on social networks.
So each of these rows correspond to different customers
and for each of these customers,
we have two features the age and the estimated salary with
which we're going to predict the dependent variable purchased, which takes
binary values zero, meaning that the customer didn't buy the SUV,
and one meaning that the customer but the SUV.
All right, let's do this.
Let's see if decision tree classification can beat
the previous accuracy we got so far, meaning 93%.
So without further ado, let's open that with Google Colab.
Choose your favorite.
And I'm going to put it here because this is our next classification model.
All right. Perfect.
So once again this implementation results from that classification template
we made in the first section of this part three
when we implemented the logistic regression model.
And therefore the only cell that changes here in this implementation
is, as usual, that cell where we build and train the classification model.
Right.
This cell here and all the rest, you know, all the other cells are exactly the same
as in the logistic regression code template
or you know, the classification code template,
because indeed we use the same variable names classifier.
And then x train x test everything is the same except the cell.
So once again we're going to re-implement this cell.
But to do this we need to create a copy because this is in read only mode.
So right now we're going to create that copy
on which we will be able to re-implement that cell.
All right.
So let's scroll down again
to find that cell where we build and train the decision tree classification model.
Now let's put it in the trash immediately because I don't want you to see,
you know, the name of the class, because indeed I want you to find it on your own.
So there you go.
Now is the time you press pause on this video to find the right class
name that allows us to build the decision tree classification model.
You will have to either look for it directly through an online search
or that other option is to look for it inside the scikit learn API.
And this is exactly what we're going to do together.
And all right let's do this.
So let's go to the scikit learn API to find the class
that allows us to build a decision tree classification model.
All right.
So API
and by memory you know let's suppose actually that I have no idea of the module
or even the class that built this decision tree classification model.
So here I'm scrolling down, you know, to observe the different modules.
Maybe it is an ensemble method because you know, I know that
random forest we built, you know, the Random Forest Regressor in part two.
Random forest is an in simple method.
But no, here we don't see the decision tree.
So let's scroll back down again.
Which makes sense, right?
Because the decision tree is just a single model.
It is not an ensemble of models.
All right. So many learning metrics. No, no.
You know it's really important
that you get familiar with this API because the more you get familiar,
the more expert you'll become and the better you'll juggle
with all the machine
learning tools you know, besides the one that I'm giving you in this course.
All right, so here I'm scrolling down more.
All right.
Preprocessing, random projection, semi-supervised
learning, support vector machines, decision trees.
There we go.
You know, usually the module you're looking for in the circular
API will have the same name here as the model you want to build.
Right.
And you know, this is organized in alphabetical order.
So that's why I wanted you to do this exercise.
It's actually very easy to find what you want.
All right decision trees.
Now which one do we want to get among these.
Well that's of course the first one.
You know, that was the one we used in part two regression.
But now we're doing classification.
So we want the decision tree classifier class.
All right.
So now what do we have to do first.
Well let's do you know what do we have to do
anyway which is to import that class.
And so I'm copying this.
And then back in my copy we're going to create a new code cell.
We're going to paste that.
And once again we're going to start from scikit learn.
And then the tree module by scikit learn.
And from that tree module we're going to import
the decision tree classifier.
So that's the first step right.
You know it by heart. Now.
And now the second step I don't even have to tell you.
It is of course to create our classifier object,
which will be created as an instance of this decision
tree classifier class and which will represent nothing else.
Then the decision tree classifier model.
All right. So here we add some parenthesis.
And now the second question is what do we have to input here as parameters.
You know if this decision tree classifier class.
So let's see.
Let's go back to the documentation to scikit learn API.
And well we will just change one you know default
value of the parameters which is this one criterion.
So the default value of criterion is Gini.
But with respect to what you learned in the theory with key rules
intuition lecture, we're going to choose an entropy criterion.
So the criterion is of course the function to measure the quality of a splits.
And that quality is measures by entropy.