In this video, we will see how to train our model using shin gauge method.
So we learn to shrinkage.
Method one is rage.
And one is lasso.
So we'll be running the data first.
Carondelet integration.
We need to use a library called Delimit.
So if you have it installed, you can find it here.
It is delimit if you don't have if you don't have it installed, you can install it.
I think installed packages.
I have it installed.
I just click it.
Now for bridge division, we also need to segregate our data in two dependent very well and independent
variables.
So we'll create a separate variable called X.
Which will get all the independent variables.
So we'll wait X is equal to model matrix.
Moral matrix and price.
Lot dot
com and they basically be and after this in squared Blackett, we were delayed that we do not want deep
price Kollam so place Calame was the first column.
So after this comma, we'll write minus one so that we do not get the price column.
Next on this.
So X as 15 variables.
It does not have the sixteenth variable we just place.
If you want to look at it, you can click on it.
But let's move forward.
Now we will create a Y variable which will have the dependent variable.
So I do have Y is equal to the F dollar price.
So now X has all these independent videos.
Why has the dependent variable?
Now, if you remember in digitization there is an added parameter called lambda.
And we want to find out that critical lambda for which the edit is minimum.
So really create a grid of lambdas and we'll run the model for all those lambdas and we'll then find
the lambda, which has the lowest added.
So to do that, we will rate grade is equal to.
And there's two part sequence in common, minus two.
At first plaited, I'll explain it in a bit.
So then come on, minus two comma length is equal 200.
Is equal 200 hundred.
Next on this, no, let us look at this grid variable, will they Grid and Bressington?
You can see that it has undervalues since we told that we want to Lindop hundred and it starts, Fred.
And it's about 10 because TNT first value and it will end at ingestible minus two because that was the
end point within the this range.
It has divided this range of 10 to minus two in 200 different values.
And for all those value, we have a grade of 10 this two part that value.
So this is the value of lambda it very spontaneous, about 10, which is very high, number two, Tanaiste,
but minus two, which is a very small lambda.
So we have a grade of lambdas now.
We are going to put these lambed does this X and this way into our model, so we'll create a lemon discourage.
Is equal to GLAAD.
Nick.
And within bracket will rate X, comma, Y, comma, I'll fight equal to zero.
This better.
I'll fight takes two values, zero for reintegration and one for the lasso.
And the last bet I made that is lambda, which will be equal to grade.
So there us is this.
So we have elements does Ridge as a variable, we can look at a summary of this created model, but
it won't make much sense to us.
The first thing we want to find out from this is the critical value of LAMDA for which we have the best
model.
Glue that we need to compare the R-squared values or some barometer like that.
So DNA really gives us the option to use cross-validation.
So it has a inbuilt cross-validation function.
We'll be using that to find out the best lambda clue that will wait.
S.V. Underscore, Rick.
It get CVD out the eliminate.
X.com and Viacom are all physical digital.
And the last parameter is less magical low-grade.
And now we'll look at this.
See if it will rain blood.
And within brackets relate S.V. Fit.
You can see this is a graph of log values of lambda against the mean square amongst all these means
good at our values.
We want to find the point where they mean squared error is lowest.
And corresponding to that point.
You want to find the lambda value.
So you can see from this graph it seems to be somewhere here or let us find the optimal value lambda
to find that optimum value of lambda will rate optimum.
Lambda OPB underscore lambda.
Yet S.V. underscored for.
Dollard Lamda Mean.
So for the S.V. fit very well, it has all the lambdas.
We are taking our day lamda for which deman means water that is minimum to let us run this formula.
So we have a new variable called Optimum Lambda created here.
So this optimum lambda, this now has the value of lambda for which our mean square error is lowest.
If you want to find out, because funding R-squared value of the model, there are optimum lamda is
this.
We have to write a couple of lines of code.
So first thing we need to find is the total to Moscowitz, which is VSS get.
Some.
I went in bracket
differential, actual away from the mean.
So mean why?
And this all defense to be squared.
So we'll put a date to.
So we will run this and we'll get it to assess witchetty total Thomas squirts.
Now we want to find out, do they do it's almost gourdes or that we need to find the predicted value
of way from this fate.
So we'll first find you predicted values, a way to get that the right way and just go to a.
Get predict.
L.M. underscore discourage.
Comma s is equal to optimum lambda.
So the lambda value that we have, the utility of doing lambda that we are so eligible to optimum lambda.
And the x value to be used are the new X is equal to the x ray variable that we had created earlier
to let us run it.
So now we have the predicted values.
Now we want to get these let's do to Moscowitz date.
RSS is equal to some.
And let me sum of different squared of the difference of predicted from actual.
So.
Difference of predicted by underscoring minus the actual.
Which is why.
I mean, it's credit.
So next on this.
And now we have this as value.
So.
Our square is VSS minus Orissa's by diocese.
In other words, it is one minus auditors, but diocese to legislate that formula.
R-squared rescue is equal to when minus are accessed by DS.
So you can see the R-squared value for this model is coming out three point seven one nine six.
So you can use this value to compare the model to.
So this is how we first find out, do you fit using delimit?
To get debate optimally of LAMDA, we will use the cross-validation function c.v or delimit ill plotted
will find the minimum lamda will use this minimum lamda.
And this previously fitted model to get the predicted riluzole predicted values of way using those predicted
values over.
We can always find out the means Guiterrez, RSS, VSS and all of those things.
So this is how this integration is done.
LASO is exactly same.
Only that this parameter, which is Alpha, instead of being zero, it will be one.
So let us out on a limb.
Underscore Lassalle.
Is equal to eliminate.
Exactly same.
Will copy pasted.
Instead of this veto will do as one done and all the other stepped out.
Exactly same.
We can get the optimum Lambda for desautel using following the same steps.
And from that optimum lambda, we can find out the predicted values away and then get these Askwith.
You can compare these two R-squared.
And that will tell you which of these two matters is giving us the more prediction, accuracy amongst
LASO Enbridge.
So this is all we do, lasso and integration and our.