In the last video we saw how we can save our existing trade model to a file and then load it back in
and then make some predictions that get the exact same results as the original model that we save to
file.
We used pickle to do that in this video.
We're going to see how we can do the same thing with the job live module.
And again if you don't know something you can always go what is job lib
job live running Python functions as pipeline jobs and you could go through the documentation here to
see how you doing.
But let's just see an example of how we do the exact same thing here with the job live module to create
a heading go job lib change that to mark down hit shift and enter.
So the first thing that we going to do we can go from job lead import dump and load.
You might be out a guess what these two functions do.
So to save model to file we'll go dump GSL F because we're gonna say the exact same model that we did
with pickle.
So our grid search classifier we're gonna pass it file name we'll go G.S. random forest model one dot
job lib.
So that's the difference here.
We can positive file name.
We have to press equals with pickle we used up scale which is short for pickle of course but with job
Lib we do dot job lib.
So now if we hit shift and enter there it's gonna give us little output here.
Now if we go back to our working directory we'll see the same thing two seconds ago we have less random
for us Model 1 job lib and again you can change this file name to whatever you want.
See now we've got about half a dozen models just sitting in our working directory at this point we might
move them into a model's file so we come back here.
Now if we wanted to load in our job lib model you can probably guess which function we use to do that
if not we're going to go through it.
So we'll go import a saved job labor model and we're just going to import the exact same model that
we save.
So loaded job lib model equals load file name.
We just have to pass it the exact same file name as what we saved it as G.S. random.
We should be had to hit tab order complete dot job lib.
Wonderful so that's going to load it in.
Oh what have we got here.
Oh we missed inverted comma full name making typos.
Left right and center even using tab order complaint beautiful and again once the imported we can make
predictions with our loaded model.
So let's see it again make and evaluate job lib predictions job lib y reds equals loaded job leave model
don't predict x test wonderful and then once again we'll use our evaluate Fred see how this has come
in handy we defined this function a few videos ago but now we've used it at least half a dozen times
and so preventing us from having to type out a bunch of different code the same code over and over again.
So job lib y spreads shift and enter.
We should get loaded job the model is not defined we're making this loaded job model might do change
that to job lib and then this should work.
Wonderful.
So if we compare this this is with job lib.
These are with pickle seventy eight point six nine tick points and four tick.
Point eight to take point seven eight.
Tick.
So again the exact same thing with job lib as pickle.
And now which one should you use.
Well according to socket loans documentation let's have a look.
So I kid loan exporting a model exporting a model.
Model persistence.
That's the word I was looking for.
So again if you're thinking of something that you're trying to do with a library right.
Just search the name a library.
This is exactly what I do.
I typed in cyclone saving a model.
That's what I wanted to do.
I'll come up to the documentation after training a psychic line model it is desirable to have a way
to persist the model for future use without having to retrain.
That's a main benefit of saving a model right.
So here's an example.
So you can use python's built in persistence model pickle.
That's what we've seen.
And now you could also use in the specific case of cyclone.
It may be better to use job libs replacement of pickle dump and load which is more efficient on objects
that carry large numbers higher res.
Okay internally as is often the case for fitted psychic loan estimate is.
And that's what we're saving in our case right.
We're saving a fitted socket loan estimated a.k.a. G.S. CSF which is our fitted grid search random forest
classifier
but can only pixel to the disk and not to a string.
So what this is saying is essentially sometimes if your model is large it might be more efficient because
a model is made up of large number higher res a.k.a. patterns in numbers.
That's what these num pi arrays are internally full of.
That's what our classifier is probably full of just different num pi arrays with patterns between them.
That's what it's learned from the data.
So what this is saying is that if your model is large in our case our models are relatively small because
we're only working with 300 or so samples.
But if it is large it may be more efficient to use job leave over pickle.
That's the main thing to worry about there.
Alrighty so that's the crux of saving and loading a trained model.
Again we've got them stored in in our directory here.
If we needed to share this model that's something we could pass on to our production application or
to our colleagues so they could replicate our work or something like that.
Now we're really really on the homestretch.
Next we're going to let's check back at our list.
We're going to check out how we can put it all together.
I won't spoil anything before the next video so I have a quick break.
Try to say one of the models that we've trained using job liberal pickle and I'll see you in the next
video.