Wonderful.
So now we have hyper parameter grades for our logistic regression model as well as our random forest
classifier.
Let's turn each of them using randomized search CV.
So now we've got just repeat what we just said.
Got a of parameter reads set up for each of our models.
Let's change them using randomized search CV will change that into markdown.
Wonderful.
So first up we're going to change logistic regression.
Now at the moment logistic regression model is scroll back up.
He's getting the best results.
Just on a single train and test split but let's see if those results carry through to a cross validation
split which is what randomize search TV is gonna help us with.
So during logistic regression we'll set up a random seed so that our results are reproducible and then
we're going to go set up random hyper parameter search for logistic regression.
So ask for random search log rig for logistic regression and that's this log rate grid that's short
for logistic regression that's short for random forest here we're gonna get a randomized search save
a logistic regression wonderful and then we're going to go program distribution
which is equal to our log read grid then we're going to use a cross validation of 5 which is similar
to what we've seen here so five fold cross validation you could use ten fold you could use twenty fold
what you should know is that the higher this number the longer it's going to take.
So because it has to build a model for each and every single set.
So 5 is generally a pretty good value to use.
Again you might want to test that experimentally depending on the size of your data number of it as
equals 20.
So that means an Ita is means we're going to try 20 different combinations which I think will be every
single one of them because we've only got 20 different values for C here.
But that's okay so we're going to go then for both equals true which is just means it's going to output
a few things for us.
Now with that we can go for it random hybrid parameter search model for logistic regression.
So this is going to do is call randomized search the way it's gonna cross validate a logistic regression
model five times for 20 iterations.
So we should have about 100 or so examples one hundred or so different hex five times 20 is one hundred.
We're going to fit this on the training data wonderful
Oh no for RAM distribution.
Our shunt.
There we go.
Fitting five models for each of the 20 candidates totalling one hundred fits well and that's done you
see ah well it's zoomed in here so you can't really say it's going to tell us what the parameters are
that it's used and see here we can see parameter attributions see is all these different values here
solver is lived linear let's zoom back in because it's easier to say and now we can check the best parameters
by going RSA log rig dot best programs is solve a label anything that makes sense.
And the C value is zero point two three three wonderful.
And so now let's evaluate log rig dot score on our test data eighty eight point five accuracy so if
we go back up here did we beat our original result eighty eight point five.
No we've got equal to it that logistic regression model out of the box must be pretty good because we've
only turned to hyper parameters.
You could look out more different values that we could change but we're gonna leave that here for the
time being we're going to see what it's like to churn out random forest classifier.
So we're putting a little commentary here.
So now we've changed logistic regression
let's do the same for random forest classify
marked down wonderful and we're gonna do the same thing again set up random seed and we could just copy
the code from here and just change the variables we're in the habit of writing it out you know random
seed we're gonna set that to 42 our favorite number so set up random type of parameter search for random
forest classifier.
Wonderful.
We're going to R S RF Eagles randomized search save a wonderful.
We're going to put in our random forest classifier then we're gonna pass it param we'll just use Tableau
to complete so we're not doing typos here.
Daniel come on like we did before.
So we're gonna pass the RF grid which is the random forest grid so I'll hyper parameter grid up here
so we'll come down here.
What's next.
Say we're going to set that to five so five fold cross validation number of iterations is going to be
20 again.
So we're going to try 20 different combinations of these hyper parameters.
Now if we were to add these all up.
So this is 50 times for two hundred times two and or actually yeah times the space between here.
So this is gonna be a lot more.
Let's just leave it at that.
It's gonna be a lot more different combinations but we're only going to try 20 of them so randomly try
20 of them.
So verbose equals true.
Here we go.
Fit random type of parameter search model for random forest classifier.
Wonderful.
And we'll get our S F which stands for random search random forest fit we'll do it on the training data.
Why train.
Wonderful what's happened here we've got something wrong again
invalid parameter main samples lead a type header the classic main samples lead.
You notice that when I was going through it's all right.
If he didn't because I didn't notice it either.
Now run this.
So this should work.
This might actually take a little while.
I hope not.
If it does I'll pause the video and come back when it's finished well we just finished up so that took
about a minute or so on my computer it will also depend on how fast your computer's processing speed
is is how fast it goes through through this sort of process it does have to build 100 different models.
So let's check it out now that it's finished.
How do we find the best parameters of our random forest random search model.
You might already know this because you just did it with a logistic regression.
It's okay if you don't find the best parameters.
This takes a little bit of practice find the best hot parameters I'll give you a second to think of
it hint it's in a attribute it's an attribute of this one here.
All right let's figure it out.
So we're going to call the best parameter attribute.
And so this is going to show us our best parameters.
So number of estimates is the best results were 210.
This means samples split was for the best means samples leaf was 19 and the best maximum death was three.
But that was only 20 different models.
So 20 candidates we could increase this to to 100 or something that would take a little bit longer.
But in our case 20 is enough.
We're focusing on the principle here.
We could revisit this in a second to try and improve our results.
But what we're trying to do here is just minimize our time between experiments.
So let's figure out how random search random forest model went.
So evaluate the randomized search random forest
classifier model are as are at school X test why test how did it do.
Eighty six point eight eight.
Let's go back up here had it perform vs. our original scores.
All we got a little bit of an improvement.
Yes.
So this is our initial random forest model eighty three point six accuracy.
Remember if you times that by 100 but even though we've gone up a little bit we've gone up a few percentage
points to eighty six point eight.
We can check out the original one here.
Model scores our logistic regression model is still our default one is still better than the random
forest and the tuned random forest.
Now of course we might be out to try a different search different high parameter combinations to try
and push out random forest model further.
But what we might do is because we're trying to minimize our time between experiments we might push
on with our logistic regression model so now you see how we're going through this process of elimination
trying to figure out which model works best for us which doesn't work.
And then just slightly incrementing on the one that performs the best.
That's where that's where we're up to now.
We're doing the well and truly in the experimentation phase of this six step framework we're trying
out different models we're trying at different hyper parameters.
So now we've searched better high parameters for our logistic regression model backup here using randomized
search CB what we might do now is use grid search CV which exhaustively searches through hyper parameter
rather than randomly looking at different combinations of high parameters as we saw in the psychic Loan
Section grid search CV and you can look up the documentation for this as loan grid search CV grid search
CV is an exhaustive search over a specified parameter values for an estimate.
So that's what we might do now with our logistic regression model.
There's a couple of steps for high parameter tuning one you could go by hand two randomized search of
a three grid search to really narrow things down.
That's what we're at.
The process we're following now we eliminated came in with training high parameters by hand.
We eliminated our random forest model again we could always revisit these things.
This is part of the experimentation using randomized search Stevie because our logistic regression model
is performing better than now randomized search random forest model.
So now we're going to use grid search CV with our logistic regression model.
So have a little review of what we've done.
See if you could try a different hybrid parameter grid for each of our logistic regression and random
forest in our randomize search CV see if you can try some different parameters maybe increase a number
of iterations.
So if you can push those results a little bit but for now in the next video we're going to focus on
churning out logistic regression model using grid search CV.