what is going on everybody and welcome
to the sixth machine learning tutorial
in this tutorial we're going to be
talking about pickling a little bit
about scaling and then we're going to
move on into diving into the inner
workings of linear regression and of
course the other algorithms so pickling
really doesn't really have anything to
do with regression just simply is a good
a good thing to have it at your disposal
so you can save yourself a lot of time
so first of all what is pickle pickle is
just serialization of any Python object
so this could be a dictionary or in our
case it could be a classifier or a whole
host of other things so first of all
what we're going to do is we're going to
import not in caps we're going to import
pickled okay also I noticed oh yeah here
for some reason I was like double
defining why is the label thing my
mortality is showing anyway um yeah just
get rid of that if you did that
hopefully nobody followed me into that
mistake but anyway uh yeah so there's
that now what we're going to do is the
way the pickle works is like like a file
right you open it you save it right and
then when you want to use it you open it
you read it so we're going to come down
basically you know at what point would
you want to save the classifier right so
like thinking logically when should we
save the classifier well should we just
say we save it here probably not right I
mean you could you could save that
classifier but that's an untrained
classifier so you're probably gonna save
it here right so like what is the
purpose of saving a classifier it's to
avoid doing the training step because
that's a very tedious step right that
that's what's going to take the most
time in our case it doesn't really take
that long because we don't have that
much data and we were threading it but
you can imagine if you had gigabytes and
gigabytes or even terabytes of data that
you were doing this on every time you
wanted to make a prediction you would
not want to have to retrain an algorithm
so instead you can save it now of course
if you save it you know you might want
to retrain it like once a month or
something like this but you don't have
to retrain it every time you want to use
it so what we're going to say here is
we're going to say with open and we're
going to say a linear regression dot
pickle as WB as f so we're going to open
this file with the intention to write
and we're going to just use temporary
variable as F and then we're gonna say
pickle dot dum
what are we dumping we're going to dump
that trained classifier so CLF where are
we dumping it F so that dumps the
classifier and then to use the
classifier all you would actually do is
you would say like something like pickle
in equals open and then we would open
this file open with our B and then we
would say CL f equals pickle pickle dot
load and we're just going to load pickle
in so flips hello what did I do here you
a copy this paste okay so now let's go
ahead and just run this and see how we
do okay so everything works at this
point and whether or not you recognize
the fact we have actually renamed
classifier or redefined classifier here
so now what would happen if we did this
right now there is no definition of
classifier we're not saving it as a
pickle we're simply reading a pickle so
if i refresh has to reload this what we
get is there we go so you get this
information here and the pickle is saved
in the directory we're working in so
that would be if I could find it here
open it up right there's your pickle
data so in our case the pickle data or
the classifier is actually a really
really small classifier that's not big
model but anyway we save ourselves the
time of actually training that
classifier also I
said it in the introduction video but
I'll say it again remember that we live
in a time where you can spin up a server
for a very short amount of time and you
could do that so if you have like a
slower computer maybe you're only
computer is a relatively slow laptop
you've got a I don't know one of these
little netbooks or something if you are
one of those people you can spin up a
GPU cluster you can just spin up a
regular server you can spend a very
powerful computer and basically rent it
for a few dollars an hour on Linode
digitalocean or Amazon Web Services and
if you do that what you can do is
generally what I do if I'm going to use
a big server well pretty much all these
hosts work the same way you take your
data you put it on their server and like
you'll set everything up so you'll
you'll transfer all your data there
you'll set up all the code that you want
to run in all that and while you're
doing that you're using like the
smallest version they have so you're
paying like a half a penny an hour to
rent that version of a server and once
you're ready scale that server up and
then you're paying maybe a few dollars
an hour maybe even ten dollars an hour
if you're crazy scale it up run your
operation take your classifier save it
to a pickle take your classifier scale
back down the server destroy the server
or whatever and you're done so just a
couple of quick you know pointers
because we're not really going to be
talking much about that for scale for a
while but these algorithms actually you
can scale linear regression very well so
just keep that in mind so anyways that's
really all I have to say about pickling
and scaling and now what we're going to
actually be doing is writing our own
linear regression algorithm to learn how
that actually works and all that so very
exciting stuff if you have questions
comments concerns whatever leaving below
otherwise as always thanks for watching
thanks for all the support subscriptions
and until next time