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 CV what we've seen before randomized search CV with a pipeline.
There's a slight little difference here and it will 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 grid search CV or randomized search CV with our pipeline.
And now remember the purpose of using grid search CV or randomize 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 socket line 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 hybrid parameters better settings on our random forest regress.
And hopefully improve this score.
So let's type it in here.
Use grid search CV with our regression pipeline.
It's the first things first to 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.
Now we can talk about it.
So pretty processor on this score.
Double underscore sorry num double underscore computer double underscore strategy.
While 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 a look at this.
What is this key referring to.
So if we go back up here we look at our pipeline the name of this step in the pipeline is pretty process.
Okay.
So you saying you can line up those and then we're got to double underscore here so it goes to numbers
who come up and have a look into our pre processor then it's going to step into our num.
Okay.
That certainly makes sense.
So num.
And then in puta underscore strategy.
So we have to refer to num so our impurity here is our numeric transformer which is also a pipeline
which goes to impute.
Okay.
Yeah.
That's where impurity 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 mean which is what it is now
and medium.
So this is the main difference between what we've seen before is grid search CV and using grid search
CV with a pipeline.
This is where the names come in the strings at the front of all our stamps.
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 in pewter and then
the strategy variable of input.
We have to do it like this.
So let's step back through.
So we go pretty processor.
Yeah.
This one then we go up here pre processor.
Yep num.
Okay then we go up to num which is numeric transformer and we see impute to.
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 can a model double underscore well shift enter again get trigger happy model double on the school
an estimate is.
So we only need one double on the scale 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 double underscore comes in and we want to pass an estimate is which would
be the same as going in here and pressing an estimated.
But we're not going to do it there.
We can do it here.
We're going to pass it one hundred and a thousand.
So again this is just going into the model step of our pipeline which is here and passing random forest
regress to an estimate as 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 5 and then we'll
go model double underscore Max features now and we're going to pass it auto
actually yeah we'll just keep it as one there is to save some time on our grid search model double on
the score mean samples split and a pass at 2 and 4.
OK.
Wonderful.
So now we've got our parameter grid set up.
How would we run grid search saving.
So this is where we've already imported up here.
We've imported grid search CV from model selection but from completeness or for completeness what we
might do is do it again.
So from that skyline 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 S.K. learned model selection import grid
search CV and a great great Guess model.
Grid search model grid search saving deposit our model which is again here in the form of a pipeline
we're going to posit pipe grid which is this dictionary here of different parameters it's going to search
over and then we're gonna pass it see Eagles five four five fold cross validation on positive the boast
level of two so it prints out a little bit of progress for us so we can see what's happening in a Guess
model don't fit it's gonna get 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 to 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 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 Jesus model dot school
and pass it the test data
so this is the school we've got before without grid search they're just the baseline hyper parameters
of random forest regressive they might need a way 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 passed a 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 its 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
searched model it gets a score of point three three three now versus our original model score of point
1 8 2.
That's pretty damn good.
That's almost an improvement of double by searching for different hyper 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 say 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 psychic learn workflow.
We've seen how to get data ready.
We've seen how to choose the right estimate a 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 a Jupiter a notebook we've got our entire pipeline using
psychic loans 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 you'll be able to look at things
you had to look at psychic loan workflows you'll be out to look at different machine learning problems
and go Okay I can kind of figure out that I have to do have to get the data ready first I can see if
I can choose the right estimates 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 will be available in the in the resources section will be available
in a notebook you can refer back to.
But if you're looking for somewhere next of where you want to go the best place is the psychic loan
documentation.
So I get loan documentation if there's something that sticks out to you on something you want to learn
a little bit more of one of these topics that we've gone through uncovered 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 site get loan 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 gonna be a little bit overwhelming to begin with but with practice you'll be out 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 to get the resources check out the documentation and get yourself
excited for the next section.
I'll see you there.