Do we need more data?
It's time to check whether the digits dataset model
you built benefits from more training examples!
In order to keep code to a minimum, various things are already initialized and ready to use:
- The
model
you just built. X_train
,y_train
,X_test
, andy_test
.- The
initial_weights
of your model, saved after usingmodel.get_weights()
. - A pre-defined list of training sizes:
training_sizes
. - A pre-defined early stopping callback monitoring loss:
early_stop
. - Two empty lists to store the evaluation results:
train_accs
andtest_accs
.
Train your model on the different training sizes and evaluate the results on X_test
.
End by plotting the results with plot_results()
.
The full code for this exercise can be found on the slides!
This exercise is part of the course
Introduction to Deep Learning with Keras
Exercise instructions
- Get a fraction of the training data determined by the
size
we are currently evaluating in the loop. - Set the model weights to the
initial_weights
withset_weights()
and train your model on the fraction of training data usingearly_stop
as a callback. - Evaluate and store the accuracy for the training fraction and the test set.
- Call
plot_results()
passing in the training and test accuracies for each training size.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
for size in training_sizes:
# Get a fraction of training data (we only care about the training data)
X_train_frac, y_train_frac = X_train[:size], y_train[:size]
# Reset the model to the initial weights and train it on the new training data fraction
model.set_weights(____)
model.fit(X_train_frac, y_train_frac, epochs = 50, callbacks = [early_stop])
# Evaluate and store both: the training data fraction and the complete test set results
train_accs.append(model.evaluate(____, ____)[1])
test_accs.append(model.evaluate(____, ____)[1])
# Plot train vs test accuracies
plot_results(____, ____)