‫In the last video, we saw how we can put together a number of different steps using pipeline.
‫And now it's also possible to use grid search of what we've seen before, a randomized search CV with
‫a pipeline.
‫There's a slight little difference here and it'll make sense once we run the code.
‫So let's go here.
‫Actually, we'll leave a little comment.
‫It's also possible to use a grid search CV or a randomized search CV with our pipeline.
‫And now remember the purpose of using grid search CV or Randomized Search CV is to try and find another
‫set of hyper parameters we've seen searching for high parameters with a classification model, but the
‫process again is very similar with a regression model.
‫Once you kind of learn it for one psychic loan model, due to the fact of of how well the library is
‫designed, you can use those principles for other types of models.
‫And now let's see how we could use it.
‫Grid Search CV To find better hyper parameters, better settings on our random forest or aggressor,
‫and hopefully improve this score.
‫So let's type it in here.
‫Use grid search CV with our regression pipeline.
‫So the first things first is we create a grid, so pipe grid.
‫So this is going to be the grid of hyper parameters.
‫Our grid search CV is going to search over.
‫Now the main difference here comes in how you you set up the keys of your hyper parameter dictionary.
‫Let's see one for example, then we can talk about it.
‫So preprocessor underscore.
‫Double underscore, sorry, num, double underscore and puta double underscore strategy.
‫Whoa.
‫You might be like Daniel.
‫There's a lot of underscores.
‫Double underscores.
‫And what is even happening here?
‫Well, let's finish this out and then we can have a look.
‫So we're having to look at this.
‫What is this key referring to?
‫So if we go back up here, if we look at our pipeline, the name of this step in the pipeline is preprocessor.
‫Okay.
‫So you're saying you can line up those.
‫And then we've got a double underscore here.
‫So it goes to num.
‫So come up and have a look into our preprocessor, then it's going to step into our num.
‫Okay.
‫That's starting make sense.
‫So num and then input underscore strategy.
‫So if we have to refer to num.
‫So our computer here is our numeric transformer, which is also a pipeline which goes to computer.
‫Okay.
‫Yeah, that's where computer comes from.
‫And then double underscore strategy.
‫Strategy.
‫Okay.
‫So if you trace it back, it's going to say try the imputation strategy of main, which is what it is
‫now and medium.
‫So this is the main difference between what we've seen before with great search TV and using grid search
‫TV with a pipeline.
‫This is where the names come in the strings at the front of all our steps.
‫You might be wondering before.
‫What are these strings doing at the start?
‫So if we want to access our pre processes, num step the feature, the attribute of num imputation and
‫then the strategy variable of input to we have to do it like this.
‫So let's step back through.
‫So we go.
‫Preprocessor Yep, this one and we go up here.
‫Preprocessor Yep.
‫NUM Okay.
‫Then we go up to num, which is numeric transformer.
‫Then we see input.
‫Yep.
‫And then we're going to adjust strategy.
‫Okay.
‫So that's the parameters for that.
‫Now let's see how we would access our model.
‫So we go model, double underscore, shift, enter again, get trigger happy model, double underscore
‫and estimators.
‫So we only need one double underscore here because we're only going up one level.
‫So if we access our model, which is pipeline, we want to access the model step.
‫So this is where the model number underscore comes in and we want to pass and estimate us, which would
‫be the same as going in here and pressing an estimates.
‫But we're not going to do it there.
‫We're going to do it here.
‫We're going to pass it 101,000.
‫So again, this is just going into the model step of our pipeline which is here and passing random forest
‫regression and estimate us these two values.
‫Then we can do the same for other features that we've seen before.
‫So model underscore, underscore max depth.
‫Then we're going to pass it.
‫Let's go.
‫None five and then we'll go model double underscore max features.
‫Now we're going to pass it.
‫Order!
‫Actually.
‫Yeah, we just keep it as one there just to save some time on our grid search and we'll go model double
‫underscore min samples split.
‫Kind of past that too.
‫And for OC.
‫Wonderful.
‫So now we've got our parameter grid set up.
‫How would we run grid search?
‫So this is where we've already imported it up here.
‫We've imported grid search CV from model selection.
‫But from completeness or full completeness, what we might do is do it again.
‫So from Skyline Dot model selection import, you don't need to do this if you've already reported it,
‫but we're just doing it so you can see where it's from.
‫From scalar and model selection import grid search CV We're going to create GTS model grid search model
‫grid search CV We're going to pass it our model, which is again here in the form of a pipeline.
‫We're going to pass it pipe grid, which is this dictionary here of different parameters.
‫It's going to search over and then we're going to pass it, see vehicles five, four, five fold cross-validation
‫and we'll pass it over, boast level of two.
‫So it prints out a little bit of progress for us so we can see what's happening.
‫Go G's model fit and it's going to go X train.
‫Y train.
‫Beautiful.
‫And so this is going through five folds for each of the 16 candidates.
‫If you wanted to work that out, you go to.
‫So two variables here.
‫Times two, times two.
‫So that's two times two, four times two, eight times one, eight times two.
‫So that's 16 different combinations of parameters.
‫We're doing five fold cross-validation.
‫So it's going to do 16 times five, which is 80.
‫So once that's finished here, we've got an output here of of all the different versions of parameters
‫that it's doing.
‫And once it's finished, we'll be able to evaluate our grid search model using.
‫GTS model dot score and pass it the test data.
‫So this is the school we got before without grid search.
‫So just the baseline type of parameters of random forest aggressor.
‫Now you might need to wait depending on how fast your computer is.
‫You might need to wait a little while.
‫So this is why it's always, always important to be careful how many parameters you pass to grid search
‫CV because it is going to exhaustively search every single combination.
‫So what we might do is pause the video and wait until our model has finished training and then see what
‫it score is.
‫Excellent.
‫So after about a minute or so, our grid search is finished and we can see that if we evaluate our grid
‫search model, it gets a score of 0.333 now versus our original model score of 0.182.
‫That's pretty -- good.
‫That's almost an improvement of double by searching for different type of parameters using a grid search.
‫Now, we could keep this going for more different parameters, but in the sake of time, we're going
‫to leave it there.
‫And so.
‫We've covered a lot.
‫And if you've made it this far, congratulations.
‫Let's have a look here.
‫What we've covered.
‫Shift into what we're covering.
‫It should be what we've covered now.
‫So we've gone from an end to end socket loan workflow.
‫We've seen how to get data ready.
‫We've seen how to choose the right estimated slash algorithm for our problems.
‫We've seen how to fit models, slash algorithms, and use them to make predictions on our data.
‫We've seen how to evaluate models.
‫We've seen how to improve models.
‫We've seen how to save and load trained models.
‫And now we've just put it all together using a pipeline.
‫We fit everything that we did before that took multiple cells before into one cell, one cell of of
‫a jupyter notebook.
‫We've got our entire pipeline using psychic learns pipeline function.
‫Now, if you've made it this far, it's worth putting yourself on the back.
‫So congratulations.
‫We've covered a lot of ground in the psychic loan library, but as you might have guessed, there's
‫a lot more that's still there.
‫But with what you've learned so far, you'll be able to take it on.
‫You'll be able to look at things.
‫You'll be able to look at psychic learn workflows.
‫You'll be able to look at different machine learning problems and go, Okay, I can kind of figure out
‫that I have to do I have to get the data ready first.
‫I can see if I can choose the right estimate, a slash algorithm for our problem.
‫I can go through trying to fit my model to the data and make predictions.
‫Then I can try and evaluate it and improve it, save and loaded.
‫After I've done a lot of messy code, I can try pull it all together and clean it all up.
‫And don't worry, putting all this together, it's not like you're going to learn it overnight.
‫I don't expect you to.
‫Even after going through all the videos that we've covered, it's going to take a lot of practice,
‫right.
‫And hopefully you can use the resources that are available to you.
‫So all the code that we've got here, it'll be available in the in the resources section, it will be
‫available in a notebook you can refer back to.
‫But if you're looking for somewhere next of like where you want to go, the best place is the psychic.
‫Learn documentation.
‫Psychic learn documentation.
‫If there's something that sticks out to you on something you want to learn a little bit more of of one
‫of these topics that we've gone through and covered some you want to dig a little bit deeper into,
‫maybe you want to look at different classification models, regression models or clustering, something
‫that we haven't seen much of yet.
‫Go to the socket, learn documentation, go to the user guide and step through all of these different
‫categories here.
‫And see if there's a little topic here that you want to read a bit deeper into.
‫And again, it's going to be a little bit overwhelming to begin with, but with practice, you'll be
‫able to start to make your own mental models of how you can use a psychic loan library to solve your
‫own machine learning problems.
‫Now with that being said.
‫I'll see you in the next section.
‫And we're going to put everything that we've learned in the previous section section to all these tools
‫that we've learned.
‫We're going to put them together and start to work on some of our own projects.
‫So take a break.
‫Revise what we've learned.
‫Check out the resources, check out the documentation and get yourself excited for the next section.
‫I'll see you there.