In this video, we will learn how to execute bagging in Python.
But before starting, let's have a look at the documentation of bagging.
On, Eskild, on.
I have provided you the link of this documentation.
You can also search it on Google.
Just write a skillern and begging and you will get this documentation.
This is oficial, a Skillern documentation.
And if you need any help regarding any of the machine learning algorithm, you can always look at Escalon
for in-depth explanation.
So underdog top, you can see this is over Syntex.
All the parameters, suddenly Serbia.
And if you scroll down, you can get the definitions of each parameter will go by all the parameters
one by one.
So first one is the Baeza submitted.
So here you have to provide your classification or regression model on which you want to apply begging.
So for our example, we will use our Kreig classifier to apply begging method on that classifier.
Next, is that an estimated.
So you mean that we are going to make subsets of over data and create KRI on each of those subsets?
So here an estimate means the number of Baeza symmetry in the symbol or the number of subsets we want
to create from our data.
The default value is ten.
But for our example, we will use tosing.
Now next to the max samples.
This is a number of samples we want to draw from a word BFD data frame if we want to draw.
Suppose 80 percent of data.
Each time we can just write zero point eight instead of one.
So by default, it is centred one and one means hundred percent of our data.
Now the next parameter is maximum feature.
So this is for the number of variables we want in each of our estimated since in begging, we use all
the variables.
So we will use the default value of one next parameter is bootstrap.
So while taking the samples out of our original data frame, we can either take this sample with replacement
or we can take these samples out without replacement.
Now, in bagging, we always take sample with replacement.
So we will use bootstrap equal to crew.
Again, we have a barometer for bootstrap features here also.
If we are taking the subset of our features, we can either take or features with replacement or without
replacement.
With replacement means, suppose we are taking five feature auto friendly features.
We first select one feature out of friendly feature.
Then for second feature, we will consider all the 20 feature.
So there are some chances that some feature may get repeated.
Nexis or BBT, Scott?
We have not discussed auto back samples, but just to give you a small explanation.
Suppose we are taking a subset of our data for each story.
The remaining sample is known as out of bag.
Next parameter, here is one sock.
If we have previously created a bagging model, we can use the result of that bagging model to start
our new bagging model by default.
This is set to false now and job parameter is for optimizing the performance.
So if you have my deep core processor in your computer, you can select minus one.
If we select minus one, this means that we will use all the processing power of computer that.
No next says that I know mystate, since we are going to get samples of forward data and this sample,
some random sample, we can provide random estate so that we can reproduce our result.
So this is just a random number, you can give either zero one, two.
Or any integer value.
And if you stick to that value, you will always get the same result for your begging process.
Next parameter is verbose.
So while running any more than you get some messages, so verbose parameter can cruel the amount of
information you get as output during running that model.
This is not related to performance or forward backing model.
So let's go back to a.
Despite a notebook.
And here we will first create a basic classifier tree because we are going to use that classifier tree
as a parameter in our base estimate of our banking classifier.
So we'll import KRI from Escalon and we'll create a CLV creed with A, B, C entry classifier, and
you know that in bagging we grow Fullard tree.
That's why we are not providing any parameter for max depth or minimum leaf size or minimum's.
I'm Polet into Nano.
We are going for Yewtree.
Let's run this.
Now we will import begging classifier.
This begging classifier is available.
And and dot on somebody will run this and we're bagging classified name is bag underscore CMF.
This is a variable name.
Then we will call baggage classifier.
And our first parameter here is base a scimitar.
Since we want to use CCRI classifier, that's why we will give base cemetaries CnF CCRI.
Now here we want Towser increase.
That's why we are putting tousling here by default.
This value is spent.
So if you have a small dataset, you can increase this number two thousand five thousand 2000 3000 extra.
So for our example, we are taking it as Towser.
In a way, we are seeing that we are creating Towser increase tolls and different trees and we are going
to average out the result of those trees to get our final value.
Next, is bootstrap equal to true, since we wanted our subsets for each of these Towser increase to
be taken with replacement from our two regional dataset.
That's why we have kept bootstrapping to grow.
And then next, promontories and jobs equal to minus one.
Since we want full processing power of our computer.
That's why we have taken and underscore the job, says minus one.
And we are giving random status for title.
This is just a random number.
You can give zero.
One, two, three, etc..
So if I don't give this number the next time I add on the same code, I will get a somewhat different
result.
So to reproduce the same result, it is important to have them demonstrate at some concern number.
Let's create this begging object and we will foot begging object on our extreme and by train variable.
It will take some time as we are creating Towser increase this time.
Now we have 48 hour more than it may take, two to three minutes for you if you are not grinning it
on an efficient machine.
Next.
We are going to on fusion metrics, on our test data here.
These are our true values.
And instead of creating another variable, we are just calling bag underscore classifier.
And we are predicting the values for white test here.
So you can also use this instead of creating a separate variable each time and calling that video with
you.
So let's run this to create our confusion metrics.
Again, rules are for actual value, so this trend bearden's exceed that for actual values.
Your first is zero.
And second is one.
So these are four actual values and columns are footprint.
That when you saw 20, 28 cent, four zero as actual and zero as predicted.
So our model predicted this trend.
Great observations correctly.
And also this 36 odd observations correctly, because our actual value is also one for this 36.
And the predicted value is also one for this 36.
And accuracy score will be 28 plus 36, divided, whether total number of situations or we can directly
call accuracy under score scored.
So let's find out that Chrissy.
So our accuracy or more than begging, is sixty two point seven percent.
If you remember earlier.
When we were using a single digit entry, our accuracy score was first fifty four point nine percent.
Then after pruning, our accuracy score was increased to fifty five point eighty eight percent.
And now with begging, our accuracy score is 62 percent.
So you can see creating large number of trees improved our accuracy score.
And in the next lecture, we will look at the random forest matter to further improve.
This is good.
Thank you.