Exercise

# Building your own digit recognition model

You've reached the final exercise of the course - you now know everything you need to build an accurate model to recognize handwritten digits!

We've already done the basic manipulation of the MNIST dataset shown in the video, so you have `X`

and `y`

loaded and ready to model with. `Sequential`

and `Dense`

from keras are also pre-imported.

To add an extra challenge, we've loaded only 2500 images, rather than 60000 which you will see in some published results. Deep learning models perform better with more data, however, they also take longer to train, especially when they start becoming more complex.

If you have a computer with a CUDA compatible GPU, you can take advantage of it to improve computation time. If you don't have a GPU, no problem! You can set up a deep learning environment in the cloud that can run your models on a GPU. Here is a blog post by Dan that explains how to do this - check it out after completing this exercise! It is a great next step as you continue your deep learning journey.

Ready to take your deep learning to the next level? Check out Advanced Deep Learning with Keras in Python to see how the Keras functional API lets you build domain knowledge to solve new types of problems. Once you know how to use the functional API, take a look at "Convolutional Neural Networks for Image Processing" to learn image-specific applications of Keras.

Instructions

**100 XP**

- Create a
`Sequential`

object to start your model. Call this`model`

. - Add the first
`Dense`

hidden layer of`50`

units to your model with`'relu'`

activation. For this data, the`input_shape`

is`(784,)`

. - Add a second
`Dense`

hidden layer with`50`

units and a`'relu'`

activation function. - Add the output layer. Your activation function should be
`'softmax'`

, and the number of nodes in this layer should be the same as the number of possible outputs in this case:`10`

. - Compile
`model`

as you have done with previous models: Using`'adam'`

as the`optimizer`

,`'categorical_crossentropy'`

for the loss, and`metrics=['accuracy']`

. - Fit the model using
`X`

and`y`

using a`validation_split`

of`0.3`

.