it's time it's time to fit our model
here we go so so far you know hopefully
you've watched all the previous parts of
this series if you haven't that's fine
too but what what I have so far is I
prepared my data set loaded it from a
JSON file I've turned everything into
tensors and then I created a Model T F
using touch flow data has a TF
sequential model which is designed to
receive RGB inputs and output a
probability distribution for color
labels and you know again this is
somewhat of a trivial scenario but I'm
classifying data simple data with just
three values all between zero one and
nine possible categories or labels okay
so that's what I've done so far so now
that I have this this is actually like
it's always the feeders gonna be over in
like two seconds not really all I need
to do is call model dot fit so modeled
outfit now what do I need to pass to
model dot fit well the idea of model dot
fit is that I'm saying hey here's the
training data here are all the inputs
and their associated target outputs
which I have called X's and Y's now I
think I'm gonna get an error right now
let me just actually run this and I'm
going to up so let me run this and see
if I get the error that I'm expecting
yeah
so look at this Oh okay so a couple
things welcome to your life doing
machine learning shaped mismatching I
didn't even expect this error so I have
to think about this one error when
checking input expected dense input to
have shape three but got array with
shape 5643 three so i guess right I'm
sending in not just three inputs the
shape of my inputs is many so I think if
I just do aha
so I made a mistake and I used input
dimensions where what I really meant was
input shape all right let's go look at
the documentation
and see what it says there and I
actually I've got it pulled up already
okay so you can see what I specified was
input dimensions if specified defines
input shape as bracket input dimensions
Oh
so actually I don't even need those that
those array brackets there and that
should fix it there we go
but if I wanted to use those array
brackets because I'm sending in many
data points I could actually just
specify the input shape directly and
this would then have the array brackets
around it so it's a subtle distinction I
think because only input dimensions is
documented let's use that one and let's
put a three here okay so no peeps we've
got that I wonder why that didn't oh
because I didn't call fit before okay so
now I'm fitting the model hmm I don't
see an error I expected an error let's
so what happens when I fit the model
well it returns a promise model dot fit
returns a promise if you don't know what
a promise is guess what I have a whole
set of videos about what a promises and
I'm also going to be using eventually
awaitin async which I also have videos
about but right now I can just write the
dot then the prompt if it returns a
promise which I can then call a function
called
then to where the results will be passed
in and I'm just going to say and I'm
gonna use this arrow syntax that's es6
arrow syntax console dot log results and
eventually I might want to do more with
this so I'm actually gonna make it a
full function so this is what I'm saying
is once you fit the model then log the
results let's see what happens
waitingwaiting
up okay great look at this history loss
and there's my loss so it fit that model
it did one epoch and gave me a loss
great so done train the model here's the
thing I want what I want to do
ultimately so this is actually in a way
done what I want to do is first of all I
want to train the model for more than
one epoch so one thing that I need to do
here is pass in some options so I'm
gonna create a variable called options
and one thing I can specify is like
epochs I'm gonna say do it for 10 and
then I'm gonna say and let's actually
let's just say 2 right now because it's
gonna take a while so the third argument
to model dot fit is options and if I go
into tension flow yes and I look for a
model dot fit oops I was right there
already we can see now these are the
various options and I'm gonna be using a
bunch of these but epochs is one of them
the number of times to iterate over the
training data so let's rub this now and
you don't have to do I'm gonna I don't
think we need all of this printing stuff
so I'm gonna get rid of some of the
earlier printing things because I don't
need to look at all of that so much so
let's run this whoops
options is not defined I spelled that
wrong I guess I still have 44 and 45
console logging stuff which I don't need
I didn't get an error that I expect to
get which is kind of interesting and oh
you know why one thing that I want to do
is I want to update you know at the time
of this recording I think the most
recent version of tension flow chess is
zero point eleven point seven well and I
when I was previously recording I was
using 0.4 and I think some things have
changed so it was alright so let's let
this run it's it's running four to
epochs right now it's finished and I can
look at the history and I can see both
lost so we can see the loss went down
for the second a pocket that's great now
let's run this over ten a pox and let's
run this and let's just console log
results dot loss by the way or what was
it is it results dot history dot loss
might be that now let's look at what it
is a history history dot loss okay so
let's do this
whoops I don't need that let's go back
here
hit refresh and waiting I'm gonna edit
out this waiting part okay great so look
at this over ten a pox the loss is going
down this is good this is what we want
to see now here's the thing
what's it using to calculate that law
huh oh there's so much to discuss I
gotta get myself organized my thoughts
here I want to here's I think maybe
maybe I've done this video I'm really
really drugged breaking this into lots
of small parts and really what I've done
now is call modeled fit with one single
option the two things I need to do that
are next one is I need to figure out
what's getting that law like what data
is it using to calculate that loss is it
the training data didn't I talk about
testing data and validation data maybe
thinking about that it's a point so I've
got to deal with that number two is I
would like to the point of this is I'm
in a p5 sketch and I could say function
draw background zero and I can run this
but look at this it just is loading up
there all the while while it's training
I've locked I don't have any ability to
run an animation I want once it finishes
I see the canvas
I want the canvas to animate while it's
training and I want to see the loss over
time I want to have that reported back
to me so those are the two things that I
need to do I think I can tackle the
training the testing and validation Dana
thing right now because let's do that in
this video and I'm going to add the
animation stuff in the next video so
first of all okay so I have my data set
my data set has I think it was five
thousand six hundred and forty three
elements data points in it I said at the
very beginning of this series where I
was preparing the data set that a
typical thing to do is divide the data
and again this is really small for
proper machine learning model robust I
probably want to have a much larger data
set but this will actually kind of work
just fine as we'll see I want to use
probably the 80/20 rule saying that
eighty percent is actually the training
so I want to just only use why does it
it's because the keyboard is next to
this it's going so I want to I want
these X's and Y's to only actually be
80% of that original data so I'm not
doing that I'll maybe I'll add that in
another point that can be an exercise
for you of the view for you as the
viewer to take out 20% or maybe because
my data centers are small just take out
10% of the data so that's what would be
used to test the model after I finished
training it but while I'm training it
while I'm actually training it figuring
out well how many input notes do I want
a I want
what are these sort of taper parameters
what are the parameters of this system
that I want to try different things how
many pucks do I want to train the model
for what what batch size do I want to
use all these things are known as hyper
parameters the parameters of the during
the training process if I want to be
playing around with those
I need a separate data set to compute a
loss that's not part of the training
data but also is not part of my testing
data that it would use when I'm
completely done training that's what the
validation data is the validation data
is basically a test dataset but it's not
your test data set when you're done and
you're ready to publish your model
it's your test dates that while you're
doing all the training intensive like
that jazz has a configuration option for
models outfit that just says hey use
this much as the validation data so
let's go back over here let's go back to
the documentation and we can see here
now I could specify the validation data
or I could just specify validation to
split which is a float between 0 & 1
it's the fraction of the training data
to be used as the validation data so if
I come back here and I just add an
option validation data and I say 0.1 I
want to use 10% of my training data as
the validation data that's what's going
to be used to calculate the loss but
it's not part of the Train down now
there might be an issue I also want to
make sure I have shuffle on shuffle is a
parameter that shuffles the training
that each epoch because you don't always
want to train with the data in the same
order as you're tweaking all the weights
and stuff as it's doing its training if
it's in a different order it's gonna
help it out but the validation data I
think I looked at this before is before
selected before shuffling so it's
selected from the last sample so I might
have a slight issue or if for some
reason the order my data is in there's
something weird about the end of it is
all one label or something I probably
won't like shuffle it myself manually
but let's not worry about that right now
but that's something definitely to be
cautious of well this is so much to
think about
all right now so now that we've added
shuffle and we've added 10% as
validation data
let me now run this again okay so we
finished it trained now with the
validation splits and Oh breaking news
breaking news getting information from
the chat that I wrote validation data
here interested to give me an error so
if I wanted to give it specific
validation data that's what I would use
but I want to use validation split thank
you for to the chat for correcting me
there let's try running this again let's
give it just more epochs a little bit
more time to wait let's give it 50 all
right okay it's back let's take a look
at our loss function over 50 epochs and
we can see it's going way down to 0.75
you can see it's kind of stopped
actually we kind of accidentally might
have you can see how it kind of goes up
now we can see like it's not able to get
any better so we might not even need 50
epochs but we might want to tune various
parameters to see but I'm not gonna
worry about all that right now the point
is I have now trained the model using
model that fit shuffling the data with a
certain validation saving 10% for
validation I'm not doing proper testing
data yet that would come later and 50
bucks okay so in the next video what I
want to do is make it so that I can run
an animation I can graph the loss
function over time all that sort of
stuff and not have it kind of like
blocking right the way it's doing right
now the animation thread and then of
course I also need to allow the user to
specify a color and get a label for that
so those are the next two steps I need
to do see you in those videos
[Music]