Hello my friends, and welcome
to the final practical activity of this part three on classification.
And now we're all going to go into part three classification.
Then to implement the final classification
model of this part three the random forest classification model.
All right. And we're going to start with Python.
Of course.
And inside this folder you will get the same two files
for the implementation of this classification model.
And the social network ad data set,
which contains 400 observations corresponding to 400 customers.
You know, each row is a customer, and for each of them we get the two
features age and estimated salary with which we're going to predict
this dependent variable purchase which tells if yes or no,
each customer but an SUV from this car dealership.
And then once we train this model to understand the correlations
between these two features and the dependent variable vector,
we will be able to predict which new customers will buy
that brand new SUV just released by this car company, and therefore, we'll be able
to target the best way our customers through beautiful ads on social networks.
All right, so let's do this.
Let's start the implementation random forest classification.
And let's open this with either Google Collaboratory
or Jupyter Notebook, whatever is your favorite.
All right.
So right now it is opening the notebook loading it, laying it out.
And here is the random forest classification implementation
which results once again from that classification template
we made in the first section on logistic regression.
So all these cells here are exactly the same as in logistic regression.
You know, with the same variable names and everything except
this cell where we build and train the
the classification model here, the random forest classification model.
So we're going to re-implement that cell.
And since this is in read only mode so that you can all access it.
Well we are going to create
a copy of this file by clicking here on save a copy in Drive.
This creates a copy and there we go.
We will be able to re-implement that cell to train
our random forest classification model on the training set.
All right.
So first let's remove that cell.
And now now is the time.
Where are you going
to press pause on the video to of course implement this yourself.
And also to learn how to be independent in machine learning and learn
how to get familiar with that scikit learn API,
which is the way you're going to find the information you need right now
to build this random forest classification model.
All right.
So let's do this together.
Let's go to the API and let's find that class
that we need to build a random forest classification model.
All right.
So here as opposed to before we won't find the model.
We need easily you know by scrolling down for example down to Random Forest.
Because know
the name of the module
is not random forest as it was the case with the previous classification models.
This time it's actually right here it is.
And symbol method.
And the name of the module is exactly and symbol.
So that's where you had to find.
But you know if you looked for it by scrolling down that's fine.
Because really I want you to get familiar with the scikit learn API.
And so now the question is among all these and simple methods
where is the one we want.
Well, that's of course this one random forest classifier.
Hard to miss right.
So we're going to click this link.
And there we go.
This is the random forest classifier class with all the parameters.
So check them out. We want enter all of them.
But let me tell you right now the ones we will enter the first and most
important one is the first one actually and estimators, which is of course
the number of trees you want to have in your random forest classifier.
Right? Number of trees in the forest.
Then once again we'll choose another value of the criterion.
And that's in order to be aligned with what you learned in the theory.
You know, with key rules, intuition, lectures.
He taught you about the random forest classification model with
the entropy criterion.
So we're going to select this.
And that's it. No more parameters.
You know for the other parameters here we'll just keep the default values.
However we will just add a random state parameter and set its value to zero
just so that we can have the same results displayed on our notebook.
All right.
So first let's copy this.
You know the name of the class in the module right.
So I'm copying this.
Going back to our implementation creating a new code cell here pasting that.
And then remember we have to start from.
So from the scikit learn library.
Then from the assemble module of the scikit learn library.
And then remember we need to add here import.
Well that random forest classifier
which will allow us to build this random forest classification model.
And speaking of building it, well that's exactly our next step here.
We're going to build the classifier through this
classifier variable, which will be nothing else
than the instance of the random forest classifier class, therefore nothing else.
Then the random forest classifier model itself.
So here I'm copying this and basing it right here, adding some parentheses
and there we go.
Now let's add our two parameters.
You know, the ones of which we're changing the default values.
The first one is an T maters.
So that's number of trees in the forest.
The default value is actually 100.
But you know it will be totally fine with ten estimators.
You know ten trees in the forest.
Why is that?
That's because our data set is actually quite simple.
It only contains two features and only 400 customers, you know, 400 observations.
So we will definitely be fine with only ten trees in the forest.
All right. And feel free to try out the numbers if you wish.