‫OC.
‫In the last video, we train the model on a subset of the data, a.k.a. allowing each estimator so 100
‫estimates to see 10,000 different data points rather than all 400,000 or so.
‫And we saw a fairly big decrease in computing time.
‫So our model trained faster now.
‫What we might want to do is because we can experiment a bit faster now, is try to find some ideal hyper
‫parameters that are a bit better than what our random forests regress aggressor defaults with.
‫So let's have a look.
‫And if you've had to think about it, you might have come across or thought of the idea of tuning,
‫hyper parameter tuning with randomized search of something that we've looked at in a previous project
‫and some other previous videos.
‫So that's what we're going to have a look at.
‫And so if you're wondering what randomized search curve is, remember, we can always look up the docs.
‫But what we'll do is actually maybe we'll just create a cell.
‫Let's have a look at the code first from SRC learn how would we import it?
‫Model selection
‫randomized search CV and remember.
‫Whatever machine learning model you're working with, you can always go insert the model name.
‫So in our case, random forest regress are hyper parameter tuning.
‫And this will give you some information on how to turn your random forest regress or your random forest
‫in general.
‫So that's one way to do it.
‫The other way is from the way that we've seen is randomised search.
‫CV Oh actually let's be real here.
‫There are many different ways to do it, but if you remember what randomized search CV does, if not,
‫that's okay.
‫Randomized search.
‫CV.
‫Grab the documentation.
‫So randomized search on hyper parameters.
‫Basically we create a parameter distribution which kind of looks like a dictionary and randomize search.
‫CV is going to take our model or estimate or in psychic loan terms and search across this parameter
‫distributions or dictionary for the best hyper parameters for our model.
‫So that's what we're going to create.
‫So different random forest regression, hyper parameters and we'll go here.
‫RF Grid nice and simple for the dictionary.
‫This is the parameter distribution that I was talking about and we might go over and estimate us.
‫Remember, if you're wondering where these came from, don't forget you can always search up here random
‫forest, regress, a height, parameter tuning, and you'll find a fair bit of information on basically
‫almost any machine learning model that you can think of, of different ways of how to tune the height
‫parameters.
‫Because, again, this is not a perfect science.
‫This is a whole bunch of trial and error trying to figure out how things are going.
‫And so what I'm doing here is I'm setting up a number of different values that randomized search is
‫going to go through, try a certain number of calculations or combinations of them, and then figure
‫out which ones achieve the best results.
‫Because that's what we're after, right?
‫We're after a model that boosts us on the Kaggle leaderboard.
‫That's what we're trying to do with our default model with no churn type parameters.
‫We're sitting and only 10,000 examples.
‫Mind you, that's the bigger one there.
‫We're sitting at around eight here, so that's not bad.
‫So what else are we churning here?
‫We've got number of estimators, max depth.
‫These are all different parameters of the random forest means samples, split min, samples leaf and
‫then we'll go max features.
‫That's another good 10.51 square root order.
‫And then we also might go max samples.
‫So we might also set this to 10,000 because we saw that before max samples increase how fast our model
‫can find patterns in the data because it's only looking at 10,000 random examples rather than 400,000.
‫That's in our training set.
‫So in the spirit of trying to reduce the time between experiments, we'll set that to that instantiate
‫randomized search CV model.
‫We'll call this RS model really creatively randomized search CV and we'll pass it a random forest regression
‫with end jobs equal negative one and also random state equal to 42 for consistency.
‫Remember that's similar to setting NP random seed and then we're going to pass it our parameter distributions
‫which is RF grid, which is what we've just instantiated up here and an editor, we usually do it for
‫about 20 or so while I like to do it for about 20 or so for the first time.
‫But we might change that.
‫We might see why CV equals five.
‫Remember, that's cross validation with both equals.
‫True.
‫And the reason why we're going to reduce this will probably only do it.
‫How much time do we have?
‫Maybe only to reason being, as you might know, what has happened here.
‫Maybe that rent really fast.
‫I'm not sure why.
‫We'll check that in a second.
‫But that's alright.
‫Maybe five five's enough because I've already gone through this this process.
‫But I've set an ETA to 100.
‫But that took like two and a half hours on my machine.
‫So you could set this to whatever you want, whatever you have time for.
‫But start low.
‫Because if we were to set this to 100, this cell might run for a couple of hours and say, well, if
‫we were going home, we might set this to run for 100 and run overnight or something like that.
‫Or if we had a lunch break, we might set it to run over a lunch break.
‫That's what I used to do when I was working at a technology company in my city.
‫I would run models over my lunch break and while I was eating food and the computer was just calculating
‫away, in our case, we're just going to set this to five and what we'll do.
‫Oh, that's why it ran so long, because we didn't even fit it.
‫That's why this time is so small.
‫Our model got fit.
‫So what this is going to do, actually two's enough then, because I thought this confused me, but
‫I realized we didn't fit anything.
‫That's why it went so fast.
‫Sorry.
‫This is what we can do.
‫We go fit the randomised search CB model.
‫What this is going to do, it's going to fit two iterations.
‫So randomized search is going to pick two different combinations of parameters from here, assign them
‫to our random forest or aggressor and then fit it to the training data.
‫And remember, it's only on 10,000 samples for the maximum and it's going to tell us well, we'll be
‫able to find out in a second which are the best parameters.
‫So because we're doing two iterations and we're doing a CV value of five, there's still going to be
‫ten different fits.
‫So this might take a minute or so.
‫So we might time travel again.
‫And I know we said we can only time travel every so often, but we unlocked a superpower going through
‫this project because we're doing so well, well time travel until this cell is done and we're back.
‫So that took my MacBook Pro just under 2 minutes.
‫Right, to try out two different iterations with five fold cross-validation across a bunch of different
‫hyper parameters.
‫And now even though this took about 2 minutes, it's still far less than our original seven minute model
‫trial that we did.
‫Right.
‫And a few videos ago, because we've set max samples to equal 10,000.
‫And now because we have a trained model with randomized search CV, we can find the best model type
‫of parameters that randomize search found for us.
‫And remember, we've only set this to two.
‫So if you have more time or more compute power, you might set this to something like 100 and find the
‫best parameters from that.
‫But we're only doing two for this case and we go here.
‫RS Model dot based params.
‫It's going to tell us, okay, so this is what the best parameters that it's found not only estimate
‫is min sample split 16 min samples leave 10,000 max samples because that was only one value max features
‫auto max depth ten and now remember, these might not be the best model high parameters because we've
‫only searched for two different combinations, but we're going to work with them for now.
‫Evaluate the randomized search model show scores.
‫Our beautiful show scores function.
‫We're going to pass it the RS model.
‫Now, we may or may not see an improvement here in our evaluation metrics that we've used before.
‫Yeah.
‫So we actually see that this has worsened.
‫That's okay, right.
‫Because as I said, we've only tried two different combinations.
‫And now in a past notebook, in a past project, when I was setting up for this project, I have actually,
‫as I said, tried and ETA equals 100.
‫And I took a little break and I went and had some food because it took my computer just over 2 hours.
‫And so we'll have a look at the best type of parameters.
‫My computer found in 2 hours of searching, and we'll have a look at how they go in the next video.