‫Wonderful.
‫So now we have hyper parameter grids for our logistic regression model as well as our random forest
‫classifier.
‫Let's tune each of them using randomize search CV.
‫So now we've got just repeat what we just said.
‫Got hyper parameter grids set up for each of our models.
‫Let's churn them using randomized search CV.
‫We'll change that into markdown.
‫Wonderful.
‫So first up, we'll go turn logistic regression.
‫Now, at the moment, our logistic regression model, if you scroll back up, is 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
‫CV is going to 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.
‫RS For random search log reg for logistic regression and that's this log reg grid that's short for logistic
‫regression.
‫That's short for random forests up here.
‫We're going to go randomised search.
‫CV Logistic regression.
‫Wonderful.
‫And then we're going to go parameter distribution.
‫Which is equal to our log red grid.
‫And we're going to use a cross validation of five, which is similar to what we've seen here.
‫So five fold cross-validation.
‫You could use ten fold you could use 20 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 five 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 itas equals 20.
‫So that means an ETA 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 BOEs equals true, which is just means it's going to output a few things
‫for us.
‫Now with that we can go fit random hyper parameter search model for logistic regression.
‫So what this is going to do is call randomized search TV.
‫It's going to cross validate a logistic regression model five times for 20 iterations.
‫So we should have about 100 or so examples, 100 or so different tests.
‫Five times 20 is 100.
‫We're going to fit this on the training data.
‫Wonderful.
‫Oh, no.
‫Firearm distribution options.
‫There we go.
‫Fitting five models for each of the 20 candidates totaling 100.
‫Fitz Wow.
‫And that's done, you see.
‫Oh, well, it's zoomed in here, so you can't really.
‫See it's going to tell us what the parameters are that it's used and see here we can see parameter distributions.
‫C is all these different values here solver is lib linear.
‫Let's zoom back in because it's easy to see.
‫Now we can check the best parameters by going RC log rig bess params.
‫Is Salva labelling?
‫Yeah, that makes sense.
‫And the C value is 0.233124.
‫And so now let's evaluate log rig dot score on our test data.
‫88.5.
‫Accuracy.
‫So if we go back up here, did we beat our original result?
‫88.5?
‫Hmm.
‫No, we got equal to it.
‫That logistic regression model out of the box must be pretty good because we've only tuned to hyper
‫parameters.
‫You could look up more different values that we could churn, but we're going to 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 in a little commentary here.
‫So now we've turned logistic regression.
‫Let's do the same for random forest classifier.
‫Knock down.
‫Wonderful.
‫And we're going to do the same thing again.
‫Set up random seed.
‫Now, we could just copy the code from here and just change the variables, but we're in the habit of
‫writing it out, you know, random seed.
‫We're going to set that to 40 to our favorite number.
‫So set up a random type of parameter search for random forest classifier.
‫Wonderful.
‫And we're going to go RS RF equals randomized search.
‫CV Wonderful.
‫We're going to put in our random forest classifier and then we're going to pass it param.
‫We'll just use tab order complete.
‫So we're not doing typos here.
‫Dan, you'll come on like we did before, so we're going to pass it the RF grid, which is the random
‫forest grid.
‫So our hyper parameter grid up here.
‫So we'll come down here.
‫What's next?
‫Save.
‫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 four, 200 times two and.
‫Or actually yeah.
‫Times the space between here.
‫So this is going to be a lot more.
‫Let's just leave it at that.
‫There's going to 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.
‫Then we go fit random type of parameter search model for random forest classifier one, two, four and
‫we've got RS ref 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 made samples lead to a typo.
‫The classic means samples laid.
‫I hope you notice that when I was going through it's alright if you didn't because I didn't notice it
‫either.
‫Now we'll run this.
‫So this should work.
‫This might actually take a little while.
‫Hope not.
‫If it does, I'll pause the video and we'll come back when it's finished.
‫Well, we just finished up, so that took about a minute or so on my computer.
‫It'll 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 can 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 high parameters.
‫I'll give you a second to think of it.
‫It's an attribute.
‫It's an attribute of this one here.
‫All right, let's figure it out.
‫So we're going to call the best params attribute.
‫And so this is going to show us our best parameters.
‫So number of estimates is the best results were 210.
‫The best mean sample split was for the best min samples.
‫Leaf was 19 and the best maximum death was three.
‫Remember, 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 our random search, random forest model went.
‫So evaluate the randomized search.
‫Random forest.
‫Classifier model now.
‫RS SRF Score.
‫X test.
‫Y test.
‫How will it do?
‫86.88.
‫Hmm.
‫Let's go back up here.
‫How did it perform versus our original scores?
‫Oh, we got a little bit of an improvement.
‫Yes.
‫So this is our initial random forest model, 83.6 accuracy, because remember a few times at 100.
‫But even though we've gone up a little bit, we've gone up a few percentage points to 86.8.
‫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 able to try a different search, different high parameter combinations
‫to try and push our 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 imprinting on the one that performs
‫the best.
‫That's what we're that's what 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 out different hyper parameters.
‫So now we've searched better high parameters for our logistic regression model back up here.
‫Using randomized search of what we might do now is use grid search CV, which exhaustively searches
‫through hyper parameter rather than randomly looking at different combinations of parameters, as we
‫saw in the psychic loan section Grid Search CV And you can look up the documentation for this scale.
‫Learn grid search CV Grid Search CV searches 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 to randomised search CV three grid search to really narrow things down.
‫That's what we're the process we're following now.
‫We eliminated can with tuning height 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 CV because.
‫Our logistic regression model is performing better than our randomized search random forest model.
‫So now we're going to use grid search with our logistic regression model.
‫So have a little review of what we've done.
‫See if you could try a different hyper parameter grid for each of our logistic regression and random
‫forest in our randomized search.
‫CV So if you can try some different parameters, maybe you 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 tuning our logistic regression model using
‫grid search.