Machine Learning (Part 9)
Neil Haddley • June 17, 2022
MNIST
The MNIST database of handwritten digits has a training set of 60,000 examples, and a test set of 10,000 examples.
The digits have been size-normalized and centered in a fixed-size image.
I found that Keras is aware of the MNIST database. I loaded the database using the mnist.load_data() function.
I viewed a random image from the MNIST database using the pyplot.imshow() function.

I viewed an image from the MNIST database
normalization
Normalization refers to a process that makes something more normal or regular.
I converted each image pixel value (0-255) to a float value between 0 and 1.
I converted each label (an integer between 0 and 9) to a matrix of eight zeros and a single one.

I normalized the data
model
The keras Sequential model is commonly used.
I added a Dense layer with 512 units and 784 (28*28) inputs (there are 784 pixels in each image).
I added a Dense hidden layer with 512 units.
I added a Dense output layer with 10 units (each unit corresponding to a category value from 0 to 9).

I created the model
compile and fit
After creating the model I configured and trained it.
I used the compile() function to configure the model.
I used the fit() function to train the model.

I compiled and fit the model
predict
I used the predict() function to "recognize" the test images.

predict (recognizing the handwritten digits)