So in this video, we will learn how to do bagging technique.
We expect that after creating.
A model based on bagging the best performance of our model would be better than the broomed or the paltry.
And are bagging can be done using the addendum for this back in only.
And are bagging is like a special case of random forest in bagging.
We'll be using all the variables, only the dataset will be bootstrapped and multiple training sets
will be created.
In random forest, there may be fewer variables, but the data set will again be bootstrapped.
So since bootstrapping is being done, there is just a difference of number of variables to be considered.
If I mentioned that I want all the variables to be considered, it will be considered as bagging.
If I say that I want only a few of the variables to be considered, it will be random forest.
So we will use random forest package only to do wood bagging and random forest.
So the first thing is we have to install this package, that dumb forest.
I'll go and underscore my.
No, that the F of forest is capital.
So random forces started.
You can scroll and take that there is random forest.
You either take it hit or run the Liberty Command.
And this random forest is a No.
Next to me, Set-aside.
As I told you earlier, this adjusts for reproducibility of the desert.
So if you set the seed to zero, you and I will get these same desert, said the seed.
So now to preen our model.
We will use this random for this function, bagging is the name of the variable which will get the information
of the bag model to bagging, get information from random forest where the first parameter is formula.
Formula is the same as earlier.
We have collection as the variable to be predicted.
After that, the lesson we need to give, the variables that are going to be used for prediction are
the predictor variables.
Since we are going to use all the variables.
Therefore, I have put a dot after literally.
Next, better my dad is data, these are trained data set.
The last parameter is M.
Right.
Emigrate means how many of the predicted variables that we want to consider while building our model,
if we use all the predictors to create all the models.
This will be bagging sets in bagging.
We have all the predictors, only different training dataset.
If we reduce the number of M3, it becomes a case of random forest.
So MPRI for us is going to be 17 because entrain D2C.
If you look in the right, the strain dataset has 18 variables.
One of them is the dependent variable.
So therefore, we have 17 independent predictive variables.
So Embry's equal to 70.
I'll run this combine.
Now, there is a variable called bagging created bagging contains information of the bag model.
Now, using that model, we can predict the values on our best, it so will create new column in dataset
called S. Dollar Bagging.
So, again, to predict devalues using this model, you used to predict function.
S dollar bagging.
Very well, we'll get these values from predict function.
The first barometer is the modelling, which is Baghi, and the second parameter is the deficit.
So you predict bagging my test?
I learned this discover.
And now predicted values using the bagging model are saved in test dollar bagging with.
Now, to find out the masc of these predicted bagging values will use this formula.
Just masc bagging get value from the difference between predicted and actual values squared.
And then we find the meaning of these values.
So we'll run this command to get the MCO bagging.
Now you can see that masc bagging has value here, which is nearly 52 million.
You can compare this value with the other embassies.
This MSE was the value of a tree that we created with a depth of three levels.
It had a massive value of one hundred thirteen million when we created the full tree, that is.
There was no restriction on the number of levels.
Then we had an embassy value of ninety nine million.
When we prune the tree, we got some improvement and we had a massive rally of 97 million.
But when we are using bagging.
The MSE value as it reduced significantly.
And now the embassy is nearly 52, 53 million.
So you can see clearly there is huge improvement in prediction accuracy when we do Bagi.
The downside of using begging is.
Like earlier, you were able to plot the decision tree very easily.
That is not possible when you have done bagging.
So by trading off, interpretively, that prediction accuracy, you are able to get better prediction
accuracy.