Learning the digits
You're going to build a model on the digits dataset, a sample dataset that comes pre-loaded with scikit learn. The digits dataset consist of 8x8 pixel handwritten digits from 0 to 9:

The dataset has already been partitioned into X_train
, y_train
, X_test
, and y_test
, using 30% of the data as testing data. The labels are already one-hot encoded vectors, so you don't need to use Keras to_categorical()
function.
Let's build this new model
!
This exercise is part of the course
Introduction to Deep Learning with Keras
Exercise instructions
- Add a
Dense
layer of 16 neurons withrelu
activation and aninput_shape
that takes the total number of pixels of the 8x8 digit image. - Add a
Dense
layer with 10 outputs andsoftmax
activation. - Compile your model with
adam
,categorical_crossentropy
, andaccuracy
metrics. - Make sure your model works by predicting on
X_train
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Instantiate a Sequential model
model = Sequential()
# Input and hidden layer with input_shape, 16 neurons, and relu
model.add(Dense(____, input_shape = (____,), activation = ____))
# Output layer with 10 neurons (one per digit) and softmax
model.____(____)
# Compile your model
model.____(optimizer = ____, loss = ____, metrics = [____])
# Test if your model is well assembled by predicting before training
print(model.predict(____))