In this lecture, we will learn how to create random forest classifier in Python.
Not that we are only creating our classification, Morton, but you can also create do a regression
model using the same method, but different codes for regression.
Let's first look at the documentation of random photos on Escalon Web site.
This one is for regression.
So let's open the documentation for classifier.
If you see the parameters or almost similar to one which we have for begging, the first one is the
number of estimated.
This is the number of Greece we want in our forest.
So by default, this is spent.
But we will lose tosing for our problem.
Next is the criteria by default.
It is GENI, but you can also change it to and Groppi for Cross and Groppi.
As we have discussed with decrease.
Next are some of the parameters for our KRI, so maximum depth, minimum sample displayed, minimum
sample leaf.
We have already discussed it during our D.C. entry tutorial.
Now, this here is an important parameter.
This is Max feature.
Few remember, we select only a subset of our features to create separate trees in random forest.
For example.
In our case, we have 19 variables, so we will only take a subset of variables for each of the three.
And by default, this is set to auto.
And when we select auto, we get it squared Rudolph and feature selected.
So we have 20 features.
So a square root of 20 is around four point four.
So probably we will get four or five features if we want.
We can also give some numeric value or we can also provide a fraction of the maximum features.
So, for example, if I give point five, we will select 10 features.
So by default, the set to auto and we will also go with auto.
Now, you can go through all the other parameters, but we will stick to before you consider.
My third is almost similar.
We will first import random forest classifier.
We will create our random forest classifier object.
We will train that object using the word ekstrand, inviting data, and then we will predict the values
of by using a word to express data.
So let's imported first and then we are using these parameters.
We want those entries.
So that's why we are giving an underscore to cemetaries thousand.
We want the full processing power of war machine or computer.
That's why we are giving and underscore the jobs equal to minus one by default.
This is set to one that is our computer will only use one processor, but it is recommended that you
use and jobs equal to minus one to get the full potential of your machine.
Then we are giving random status for you to.
Since we are randomly picking their time and randomly picking features for each of our Creat.
So if we want to reproduce the same result in future, we can use random searches for to there to get
the same result as this research.
So always stick to some integer value of random.
For example, we are using 42.
But you can also use zero one, two or three.
This will not impact you.
Add more to the performance.
This is just for reproducibility of the research that we are getting.
And you already know that over M here is four or five.
Since we are giving the default value and and default value, Biton is going to take on that group of
20, which is equal to 4.5.
Let's run this.
And now we're in for to what extent and downward trend in this classified object.
It will take some time.
Now, let's grow confusion metrics on our test data.
You can compare it with your bagging deserts.
And then we're going to find out that Turistas Sports offered this model.
So what accuracy for this model is sixty three point one percent.
So if you compare the begging and begging of accuracy, score was six to 10 percent, but none for us.
We have increased that accuracy score by one percent.
So that's all for this video in the next video.
We will learn how to optimize the values of our hyper parameters.
So if you remember, there are different crede related.
Parameters here, such as Max Thep minimums and police split in our example, we have used the default
values, what we can optimize this value to get the best result for our data.
So we will use Siwiec Grid Search and we will find the best tree for our data.