Hello.
In this lecture, we will learn how to run rate and the laso in Python.
If you remember from the curity lecture, we first need to standardize our data before running the region.
The LASO.
So let's first start by centralizing over data for standardizing.
We will first import be processing from Skillern.
So we will write from Escalon Import Preprocessing.
Then we cleared the scalar object, which will store the Skilling information for what x variable rate
is scalar equate to reprocessing dot ascendants scalar.
Here is standard scalar is the function of preprocessing.
And then we will fit our extreme into this scale at.
For this hour, Scaler is ready.
Now let's first transform our extreme and to extreme scale.
So we'll write X, underscore creon.
Underscore s.
He had our repellent is skilled.
Right is skill learned, not transform.
Remember, we created this scalar object double.
Now we are transforming.
What extreme?
But on this hour, extreme is scarily variable is that.
Now let's transform our test set also.
So in right X underscored test underscore s.
Equate to a scalar, not transform.
X underscore test, just to give you a quick summary.
Here we are first creating the scaler, which is exporting the information on how to divide each rule
and each cell.
Then we are using this is scalar object to transform our extreme variable so that we can create our
Escorial variables.
Similarly, we are using the same is scalar for our test set as well.
Now we have we standardize over independent variables.
Now let's move on to red integration.
For religious aggression, we first need to import grit from Escala.
So right from a Skillern, not linear model.
Import grade.
Now, let's run a simple, rich regression.
Well, first cleared to object, LMR underscored odd
liquid to build Ridge.
And in record, we will mention our Lamela and Biton.
We call it Dulfer.
So we will write a five point two zero point five.
So here I will memorize zero point five.
And we are creating a Attridge object.
Let's fit this model, Bill, right, elements of good are not fit.
Now we will use over skill variables.
We'll write X, underscore crane, underscore s.
Comma, why underscore Craine?
We have food data, what the first model.
So let's find out.
The artist squared value on the word test data will right out to underscore the school.
Again, are to underscore is score is a function of skill and liablity.
So remember, two important before running this function.
We'll read like best.
Then will write, L.M. underscored are not predict
and in record, we'll write our best independent, weary ones, which is Xander Score Test underscore
as.
Here, our white based variable is a word or regional values.
And the second argument is the predicted values of why on test variables can see the artist square value
is zero point five four.
Now, if you remember, we can also change the value of this LAMBROS or ULFA while running red regression,
and we want to find out the value of all four Lamela for which the artist squared value is maximum for
crying out such multiple values of hyper parameters.
There is another function in Ashkelon, which is validation curves.
So we'll first import the validation curve from Escalon Library and then I will show you how to select
your optimum model from multiple values of hyper parameters.
Well, first, import validation good right from Skillern, Todmorden, selection,
import validation, good.
Now, let's first see the parameters we need for this validation, good function.
So, all right, validation.
And then we will put a question mark to open the help for this function.
If you see our first parameter should be an estimated.
So now if we want to run rigid aggression, we should great, great, our second parameter is X variable.
Our third parameter is very, very well.
These are independent and dependent variables.
Our fourth parameter is bad name.
This is the hyper parameter.
We want to change.
In this case, we want to change the alpha value.
So we.
Right.
I'll fire.
Our fifth parameter is bad membranes.
This is the values of this badam named parameter.
You want to give.
So here we will give my devil values all four alpha for our model.
Now, we are not going to discuss groups, C.V. and other parameters, one another parameter we want
to give is is scoring.
We want our moderate to score using our square.
So we will go escorting equate to are to.
Now, to summarize, what we want to do is we want to train our models for multiple values of Lamela.
So we will give multiple values of Lamela to our model.
And we want the best model out of those lamda values.
So we will run our model multiple times and will select the best model.
All of those models.
So first, let's create an array of over Lamela values.
We will write Barum underscore range.
This is our variable.
We will equate it to and be not lock space.
And then record will rate minus two, comma eight, comma hundred.
Let me explain you this lock space function, this lock space function will create hundred values between
Penrith's toward minus two and Ben Reas to deport eight.
Now, if I just.
The values of my parents change, you can see we have created a hundred different values between Penrith's
who are minus two and 10 Race to the Power eight.
We will use these values as the values of our lamda for our model.
And then we will select the best Lamela value out of this.
Different level of values.
Now let's run the accretions for our modern.
We saw validation curve earlier.
The output of validation curve is in the form of two arrays.
First is their training score.
And second is their test score.
I told you earlier that we will be scoring on Artist Square.
So training score and test score will contain the values of our score for all these different models.
Let's write Green underscored escort's.
This other what variables?
Equal to valuation of.
Remember, the first barometer of validation good was the estimate.
So here it assuming that is that it will write grade, second parameter was X value.
So we'll write X and at school Kreen underscore to S.
Next, but I mean, that is our way value.
Next, but ometer was over.
But I'm returning home.
We will write ULFA in double quotation marks since we want to change the value of this Alpha.
And then the next parameter was by Rembrandt.
We created a bad Grange variable using lock space functions.
We'll use this video.
But next, we wonder what it is scoring to be off.
Artist Kerswill, right.
Scoring equal to a square.
Fit on this.
We have created this model for all this lamanno values.
Now we will just print our CRANEY score and test the score.
So notice we have not given our test set and to this validation.
So how this validation, Gervase, calculating their test scores?
This is actually running a cross validation or give for validation on our training data.
So for each value of lambda, we are getting three values of our square.
That is because the validation group is running Kiefel validation behind the scene.
Let's just take a mean score of these three values.
So, all right, dream underscored mean
equal to and paid out mean.
Will light green escort.
Coma access equate to one, since we want the word every just to be along the roads.
Similarly, we take the mean well lose over Tesla School.
If we view this test mean Krien mean.
So these are the hundred other square values for and Greg Lambros.
Similarly, we have hungered values on our test score also.
You can also compared with our lambda values.
So for each of our Lemonheads values, these are the artist's good values we are getting.
No, we are only interested in the model which have the highest artist's good value.
So will write Max of our best mean.
This will give me the highest artist square venue for my model, which is zero point seven two four
six.
Few remember earlier our artists got to where Lou was our own point.
So I went to one nove.
We have improved it.
Two point seven dofor.
Now, another way to look at this artist square where new data is to plot a graph of this will use.
Let's load the scatterplot of this data along with our lamina values will right write asanas, don't
join plot.
And since I would never lose, you are in exponential form.
Will take a low of those values.
Overbuy is best mean.
So this is the graph for artists good values.
You can see as we are increasing our lamda.
The artists go to Ray Lewis slightly in freezing.
And after this point, the oddest really starts to decrease.
And then our artists go to value as their own.
Zero four.
Very high lamda values.
You can see we are getting the maximum artist's good value around this around this point.
So what the next objective is to find this point and find the lamda value for this point.
We see that the artists go to value of this pointis zero point seven two four six six.
Not to find the location of all of this will lose it open.
So I went to four double six will right.
And B dot.
Then our test mean
we are just finding wherever testimony is is equal to this when you.
We use Equilar design, the right mix of best me.
We are just finding out the index where this best mean value is equal to maximum of best mean value.
If we run this, you can see the location of this, Max.
That's mean.
Is that deterred index?
So let's find out.
The Lamela value of this started targeted index will rate Barum, underscore range
and then a squared record.
We will rate today three.
If we run this.
This is the Lamela value at which we're getting the maximum artist's good value.
Now you have the LAMDA values for which we have the maximum artist's good value.
We will fit our rage model again for this Lamela.
Well, you will, right?
Alem underscore our best.
Equated to a rich
and our other fiber.
Lou, is this Lemina, Lou?
We've done this, we have cleared that out.
And them are underscore the best variable.
Now, let's forget this on our training dataset.
Then I would equity, but which is X underscore, Kreen underscore.
S and then I would a variable.
We've done this, we have tried our best.
Rich Morton.
Now let's find out.
The artist's good value on our test data.
Values are to under school to.
Then why test and then Alem underscored are under.
Best.
Not predict then X underscore, test, underscore as.
Now, let's find out.
The artist could of a new photo or training data.
And this hour, artists go to a new photo ID training data ascertains zero points on five for it and
for our test data is zero point five four zero.
You will not see any major difference and not as good a value if we run underage or if we're on simple
linear regression in our case, because our data set is very small and it will hardly make any difference
which algorithm or with technique we are using to train our model in case we have hundreds or thousands
of variable and our dataset is very large.
In that case, this my thoughts would really have an answer.
What a model.
Just to get all the things we did first, we standardized our X variable.
We created this standard scalar and we use this scalar to transform our extrem and expressed data.
After that, we executed the raid more than and there we use a constant other form of zero point five.
Now, after that, we created the Angel full force, which would go into our model.
So we created a range of hundred Lambros from 10 that super to minus two, two Penrith's toward eight.
Then we use the word validation.
Got to find the optimum model.
After that, we calculated the lambda value corresponding to that more.
Then after that, we again executed the order rates more for this value of lambda.
And then we calculated the artist's good values on our training dataset and test their Dussart.
Now running LASO is almost similar.
We just have to import LASO and set off Rich.
We will import LASO from Escalon Linnean more the library, and then we will soon.
The leak cleared Lazor object as we created the LMR and that's what our object here.
We will create LMR underscore object.
Similarly, we will give overvalues.
As you can see, executing LASO is very similar to red.
We are not executing LASO here.
I recommend you to execute it on your own and find the optimum value of Alpha using validation.
Cut.
Thanks.