1 00:00:00,660 --> 00:00:07,510 In the last video we saw how we can save our existing trade model to a file and then load it back in 2 00:00:08,260 --> 00:00:13,210 and then make some predictions that get the exact same results as the original model that we save to 3 00:00:13,210 --> 00:00:14,070 file. 4 00:00:14,110 --> 00:00:16,480 We used pickle to do that in this video. 5 00:00:16,470 --> 00:00:20,530 We're going to see how we can do the same thing with the job live module. 6 00:00:21,010 --> 00:00:25,690 And again if you don't know something you can always go what is job lib 7 00:00:28,740 --> 00:00:33,720 job live running Python functions as pipeline jobs and you could go through the documentation here to 8 00:00:33,720 --> 00:00:34,660 see how you doing. 9 00:00:34,740 --> 00:00:40,080 But let's just see an example of how we do the exact same thing here with the job live module to create 10 00:00:40,080 --> 00:00:47,470 a heading go job lib change that to mark down hit shift and enter. 11 00:00:47,510 --> 00:00:54,080 So the first thing that we going to do we can go from job lead import dump and load. 12 00:00:54,150 --> 00:00:57,150 You might be out a guess what these two functions do. 13 00:00:57,150 --> 00:01:05,190 So to save model to file we'll go dump GSL F because we're gonna say the exact same model that we did 14 00:01:05,190 --> 00:01:05,860 with pickle. 15 00:01:05,910 --> 00:01:15,270 So our grid search classifier we're gonna pass it file name we'll go G.S. random forest model one dot 16 00:01:15,450 --> 00:01:16,290 job lib. 17 00:01:17,070 --> 00:01:18,410 So that's the difference here. 18 00:01:18,570 --> 00:01:20,210 We can positive file name. 19 00:01:20,280 --> 00:01:26,190 We have to press equals with pickle we used up scale which is short for pickle of course but with job 20 00:01:26,190 --> 00:01:28,010 Lib we do dot job lib. 21 00:01:28,660 --> 00:01:33,190 So now if we hit shift and enter there it's gonna give us little output here. 22 00:01:33,210 --> 00:01:39,630 Now if we go back to our working directory we'll see the same thing two seconds ago we have less random 23 00:01:39,630 --> 00:01:44,100 for us Model 1 job lib and again you can change this file name to whatever you want. 24 00:01:44,100 --> 00:01:49,020 See now we've got about half a dozen models just sitting in our working directory at this point we might 25 00:01:49,020 --> 00:01:53,710 move them into a model's file so we come back here. 26 00:01:53,710 --> 00:01:58,090 Now if we wanted to load in our job lib model you can probably guess which function we use to do that 27 00:01:59,720 --> 00:02:01,030 if not we're going to go through it. 28 00:02:01,080 --> 00:02:07,040 So we'll go import a saved job labor model and we're just going to import the exact same model that 29 00:02:07,040 --> 00:02:07,460 we save. 30 00:02:07,460 --> 00:02:13,190 So loaded job lib model equals load file name. 31 00:02:13,190 --> 00:02:19,020 We just have to pass it the exact same file name as what we saved it as G.S. random. 32 00:02:19,400 --> 00:02:22,450 We should be had to hit tab order complete dot job lib. 33 00:02:22,550 --> 00:02:26,170 Wonderful so that's going to load it in. 34 00:02:26,280 --> 00:02:27,510 Oh what have we got here. 35 00:02:27,520 --> 00:02:33,370 Oh we missed inverted comma full name making typos. 36 00:02:33,370 --> 00:02:39,820 Left right and center even using tab order complaint beautiful and again once the imported we can make 37 00:02:39,820 --> 00:02:41,590 predictions with our loaded model. 38 00:02:41,900 --> 00:02:56,590 So let's see it again make and evaluate job lib predictions job lib y reds equals loaded job leave model 39 00:02:56,650 --> 00:03:03,250 don't predict x test wonderful and then once again we'll use our evaluate Fred see how this has come 40 00:03:03,250 --> 00:03:08,710 in handy we defined this function a few videos ago but now we've used it at least half a dozen times 41 00:03:08,980 --> 00:03:14,860 and so preventing us from having to type out a bunch of different code the same code over and over again. 42 00:03:14,920 --> 00:03:18,250 So job lib y spreads shift and enter. 43 00:03:18,280 --> 00:03:26,920 We should get loaded job the model is not defined we're making this loaded job model might do change 44 00:03:26,920 --> 00:03:29,740 that to job lib and then this should work. 45 00:03:29,740 --> 00:03:30,610 Wonderful. 46 00:03:30,640 --> 00:03:33,190 So if we compare this this is with job lib. 47 00:03:33,190 --> 00:03:38,160 These are with pickle seventy eight point six nine tick points and four tick. 48 00:03:38,200 --> 00:03:40,090 Point eight to take point seven eight. 49 00:03:40,090 --> 00:03:40,790 Tick. 50 00:03:40,800 --> 00:03:44,540 So again the exact same thing with job lib as pickle. 51 00:03:45,100 --> 00:03:47,430 And now which one should you use. 52 00:03:47,800 --> 00:03:51,480 Well according to socket loans documentation let's have a look. 53 00:03:51,550 --> 00:03:56,950 So I kid loan exporting a model exporting a model. 54 00:03:56,950 --> 00:03:57,850 Model persistence. 55 00:03:57,850 --> 00:04:00,280 That's the word I was looking for. 56 00:04:00,300 --> 00:04:04,110 So again if you're thinking of something that you're trying to do with a library right. 57 00:04:04,110 --> 00:04:05,940 Just search the name a library. 58 00:04:05,940 --> 00:04:07,340 This is exactly what I do. 59 00:04:07,340 --> 00:04:09,620 I typed in cyclone saving a model. 60 00:04:09,690 --> 00:04:10,590 That's what I wanted to do. 61 00:04:10,650 --> 00:04:15,900 I'll come up to the documentation after training a psychic line model it is desirable to have a way 62 00:04:15,900 --> 00:04:19,050 to persist the model for future use without having to retrain. 63 00:04:19,170 --> 00:04:21,210 That's a main benefit of saving a model right. 64 00:04:22,110 --> 00:04:23,770 So here's an example. 65 00:04:23,770 --> 00:04:26,760 So you can use python's built in persistence model pickle. 66 00:04:26,760 --> 00:04:28,120 That's what we've seen. 67 00:04:28,380 --> 00:04:32,450 And now you could also use in the specific case of cyclone. 68 00:04:32,610 --> 00:04:38,520 It may be better to use job libs replacement of pickle dump and load which is more efficient on objects 69 00:04:38,520 --> 00:04:40,710 that carry large numbers higher res. 70 00:04:40,740 --> 00:04:46,530 Okay internally as is often the case for fitted psychic loan estimate is. 71 00:04:46,620 --> 00:04:48,780 And that's what we're saving in our case right. 72 00:04:48,810 --> 00:04:59,290 We're saving a fitted socket loan estimated a.k.a. G.S. CSF which is our fitted grid search random forest 73 00:04:59,290 --> 00:05:00,010 classifier 74 00:05:03,850 --> 00:05:07,160 but can only pixel to the disk and not to a string. 75 00:05:07,180 --> 00:05:13,150 So what this is saying is essentially sometimes if your model is large it might be more efficient because 76 00:05:13,330 --> 00:05:18,280 a model is made up of large number higher res a.k.a. patterns in numbers. 77 00:05:18,310 --> 00:05:21,280 That's what these num pi arrays are internally full of. 78 00:05:21,310 --> 00:05:25,600 That's what our classifier is probably full of just different num pi arrays with patterns between them. 79 00:05:25,600 --> 00:05:27,620 That's what it's learned from the data. 80 00:05:27,670 --> 00:05:32,950 So what this is saying is that if your model is large in our case our models are relatively small because 81 00:05:32,950 --> 00:05:36,010 we're only working with 300 or so samples. 82 00:05:36,400 --> 00:05:41,790 But if it is large it may be more efficient to use job leave over pickle. 83 00:05:42,310 --> 00:05:43,870 That's the main thing to worry about there. 84 00:05:44,850 --> 00:05:49,120 Alrighty so that's the crux of saving and loading a trained model. 85 00:05:49,120 --> 00:05:52,720 Again we've got them stored in in our directory here. 86 00:05:52,780 --> 00:05:57,220 If we needed to share this model that's something we could pass on to our production application or 87 00:05:57,220 --> 00:06:00,930 to our colleagues so they could replicate our work or something like that. 88 00:06:01,000 --> 00:06:04,520 Now we're really really on the homestretch. 89 00:06:04,540 --> 00:06:07,450 Next we're going to let's check back at our list. 90 00:06:07,450 --> 00:06:11,330 We're going to check out how we can put it all together. 91 00:06:11,350 --> 00:06:14,650 I won't spoil anything before the next video so I have a quick break. 92 00:06:14,650 --> 00:06:19,240 Try to say one of the models that we've trained using job liberal pickle and I'll see you in the next 93 00:06:19,240 --> 00:06:19,600 video.