Experimenting with wider networks
Now you know everything you need to begin experimenting with different models!
A model called model_1
has been pre-loaded. You can see a summary of this model printed in the IPython Shell. This is a relatively small network, with only 10 units in each hidden layer.
In this exercise you'll create a new model called model_2
which is similar to model_1
, except it has 100 units in each hidden layer.
After you create model_2
, both models will be fitted, and a graph showing both models loss score at each epoch will be shown. We added the argument verbose=False
in the fitting commands to print out fewer updates, since you will look at these graphically instead of as text.
Because you are fitting two models, it will take a moment to see the outputs after you hit run, so be patient.
This exercise is part of the course
Introduction to Deep Learning in Python
Exercise instructions
- Create
model_2
to replicatemodel_1
, but use100
nodes instead of10
for the first twoDense
layers you add with the'relu'
activation. Use2
nodes for theDense
output layer with'softmax'
as theactivation
. - Compile
model_2
as you have done with previous models: Using'adam'
as theoptimizer
,'categorical_crossentropy'
for the loss, andmetrics=['accuracy']
. - Hit 'Submit Answer' to fit both the models and visualize which one gives better results! Notice the keyword argument
verbose=False
inmodel.fit()
: This prints out fewer updates, since you'll be evaluating the models graphically instead of through text.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define early_stopping_monitor
early_stopping_monitor = EarlyStopping(patience=2)
# Create the new model: model_2
model_2 = ____
# Add the first and second layers
____.____(____(____, ____=____, input_shape=input_shape))
____
# Add the output layer
____
# Compile model_2
____
# Fit model_1
model_1_training = model_1.fit(predictors, target, epochs=15, validation_split=0.2, callbacks=[early_stopping_monitor], verbose=False)
# Fit model_2
model_2_training = model_2.fit(predictors, target, epochs=15, validation_split=0.2, callbacks=[early_stopping_monitor], verbose=False)
# Create the plot
plt.plot(model_1_training.history['val_loss'], 'r', model_2_training.history['val_loss'], 'b')
plt.xlabel('Epochs')
plt.ylabel('Validation score')
plt.show()