In this we do we will see the goal to train our model using subset selection techniques.
So running a model with subsect election is very easy.
And you just need to write a single line of code.
First thing we need to do is to install a library called Leap's.
So just check.
On the right hand side, if there is an in-store library already or leap's, if it is there, you can
take it.
If it is not.
You can install it, as you know, by writing it all out packages.
So I have it then to run a model with best subsects election.
We just need to write.
So will create a variable called L.M. underscored best since we are running best subsects election technique.
And this is equal to Regg subject.
And within bracket will rate price DataDot commentators, it could be if.
If we run it like this, it will go only up to eight variables.
It will not have more dented valuables.
So it will then all permutation combinations of till eight variables and it will stop at that.
If you want to run it for more than eight variables.
Since we have 15 deepening variables, we want to transport weepin variables.
We have to give additional parameter, which is N.V. Max will set.
And we max at fifteen.
So now it will go up to fifteen variables.
Let us run this.
So you can see that a just good best is not created.
Let us look at the summary of L.M. underscored best relaid somebody in the backyard.
It would be 11. would best.
If you look at it, it is a bit difficult to understand.
But if you do a military lecture, I told you that it will start with one variable, then it will go
to two variables and then we have one variable, it will find out the best model.
This is the R-squared value.
So whichever model having one variable has the highest Askwith.
It will keep that.
Then remove one, two, two variables.
It will find the highest R-squared value amongst all the models and that it will keep.
So this is the list of all those models.
So this is the best model with one variable.
This is the best model with two variables in the best model with one variable we have were properties,
the significant variable with two variables.
We have room them and for prob.
So that's how it escalated.
Ali, you've been.
Best models amongst these 50 will be selecting the one with the highest adjusted R-squared value.
You can find the adjusted R-squared value of all these models using this good.
So we'll wait.
Somebody elementary school west as well.
And then we will read L.M. underscored best dollar ETG are two, which tankful adjusted Askwith to learn
from this.
You can see we have adjusted our school values for all the 50 models.
So we can compare all these values to find out which is the highest adjusted good value and then we
can use that model.
As I selected model, if you have a lot of variables, then you'll get a lot of values it.
So in that case, if you want to find out the maximum value, you can use the.
Which tarmac's function.
So you can write which dot max.
And within its bracket, you can copy paste this above line of code.
So amongst this array of values, which is the maximum value, you can see that the eighth value is
the maximum value.
If you want to look at the coefficients that you will get in this eight model, you can do that by writing
quiff and within bracket you will write the name of the model, which is telemeters called Best comma
eight.
So you can look at the intercepts and the meta values.
But this particular model, which has the highest value of adjusted R-squared.
So you can see that this eight model has an adjusted outscored value of point seven 145.
Whereas this last model, this last model has all the variables in it.
So this is similar to a normal multiple linear regression.
This has adjusted our score, twelve point seven, one to two.
Clearly, this subset, clearly, if you select this object, it is expected to perform slightly better
on the test than this model.
Not to run forward selection and backward selection.
There is a very minor difference.
So we will light elements called forward.
Is equal to the same thing as a bell.
Just we will add another parameter, which is called Methode.
So comma matter is equal to forward.
What would you put on this?
So you can look at somebody of this method also.
On this.
Again, it has run all these have been models from this.
If you want to find out the model with the highest value of adjusted R-squared, you can repeat these
steps above and you'll find whichever modality best according to these forward stepwise selection.
Madame.
I encourage you to do that on your own.
Again, if you want to run a backwards selection method, you just need to change this forward to backward
and it will run them backwards selection technique for you.
And again, you can perform all these operations on it.
So this is how you get on best subject selection forwards to base election and backward step based election.
And once you get the model, this is how we find out the adjusted R-squared of all the models and we
select the best model out of it, depending on the model, which has highest value of adjusted R-squared.