Hi and welcome to the section where we talk about pre-processing our data before we input it into the
Keros model to train our model.
So why do we need to preprocessor our data?
Well, Keros expects data in a certain format and expects data with what they mention added onto it.
That's just because of how it how the internal structure of data is processed inside of it.
It's not a big deal.
It's nothing scary at all.
I'll show you in the code how we add that extra dimension onto it.
Then, during the data type initially is unsigned into it.
We have to change that to float to two.
Second, to leave, we have to actually normalize data between zero and one previously.
So in part to it, we normalize between minus one and one, but will work for both types of library.
So you can also do this between minus one and one.
And likewise for PI, to which you can go from zero to one.
They both work.
Generally, it's better to have zero mean zero center data like what we did in the pie to us lesson.
However, it's fine to do zero to one as well.
I frequently do zero to one, and most of my image models that I'm training, it's not going to make
a big difference, but it can in some cases, but most in most cases, it's not going to make a big
difference.
And then we do hot one, including with the label data.
So let's take a look at what we're doing here.
So for the image rows and image columns, those are basically 28 by 28, which you can see here.
Just print prints out here, just so you guys know and use that in this, these functions here where
we reshape so to reshape which we want.
This is the initial shape of our data block considered as like a block of data, 60000 entries of 20
by 28 images.
We want to get this into this shape with an X should have one dimension here.
So to do that, it's quite simple.
Actually, we just use to reshape function from no.
So it's extreme, not reshape.
We take the length of this area.
That's the shape on a sixty thousand.
We have 28 by 28 and I do one here.
And likewise, we do it for excess.
So then we keep a track of the image up here.
This is this image Roy's image columns and one.
And that's basically the number of dimensions here.
And in that case, here's where we converted to float two to both of the trading and for the X rating
and the test data.
Sorry.
And here's where we normalize.
We just divide and divide it by point zero two candidates into a float, and then we just print out
the exact day.
And here it is as a strategic test to make sure that our final shape is what we desired.
Sixty thousand twenty eight twenty eight comma one four dimensions is exactly what we wanted.
Now let's move on to hot, including one hot, including sorry, all labels.
So to do that, basically, let me explain to you what hot when encoding is.
It's basically a format where to represent the labels four or five and two or any of the 10 digits or
classes that you could be.
You basically create a rule, a column like this where you have zero one two three four five six seven
eight nine and then basically just put the 10 on one here when it represents a four and all the other
numbers would be zero.
Likewise, for five ways, for two and likewise for six, it's quite simple to understand this format.
And that's just a format that Keros uses when trying to identify the class labels.
You don't have to do this in spite of what you do.
Fortunately, so to do that, we use the two categorical function that's in the carers utilities here,
and you can see it's quite simple to implement.
We just do by train input into this function, get back to output.
Similarly, for this, and we just do a apprenticing number of classes here, we just stored a number
of classes here in this variable because this is the index.
One of this to ship gives us a number of classes now because remember, no, it's a 2D structure, so
we have to use instead of the zero.
We use one because zero would give us the number of labels, number of rows, whereas one gives this
number of columns and we get the number of pixels as well, which would just be this by this.
We actually don't need this.
I think after double check and see if we're using this somewhere else in an awkward but for now, this
is what is important here.
This two categorical.
So I'll stop there for now and we'll go back to building a model.
But before I continue, let's take a look at this.
Let's take a look at what the first element looks like.
So you can see for sure that it has been quoted into the one shot, including here you can see is 10
digits.
This is zero one two three four five.
So the first digit first class in our and image in tests in the training dataset is five.
So we'll stop that and then we'll move on.
Onto building a model in the next section.
Thank you.