Fitting the model

Next, the model is trained using the fit function. Note that, as the training of the model proceeds, we get a visual as well as a numerical summary after each epoch. The output from the last three epochs is shown in the following code. We get the mean absolute error and loss values for both the training and the validation data. Note that, as pointed out in Chapter 1, Revisiting Deep Learning Architecture and Techniques, each time we train a network, the training and validation errors can vary because of the random initialization of network weights. Such an outcome is expected even when the data is partitioned using the same random seed. To obtain repeatable results, it is always a good idea to save the model using the save_model_hdf5 function and then reload it when needed.

The code used for training the network is as follows:

# Fit model
model_one <- model %>%
fit(training,
trainingtarget,
epochs = 100,
batch_size = 32,
validation_split = 0.2)

OUTPUT from last 3 epochs Epoch 98/100 284/284 [==============================] - 0s 74us/step - loss: 24.9585 - mean_absolute_error: 3.6937 - val_loss: 86.0545 - val_mean_absolute_error: 8.2678 Epoch 99/100 284/284 [==============================] - 0s 78us/step - loss: 24.6357 - mean_absolute_error: 3.6735 - val_loss: 85.4038 - val_mean_absolute_error: 8.2327 Epoch 100/100 284/284 [==============================] - 0s 92us/step - loss: 24.3293 - mean_absolute_error: 3.6471 - val_loss: 84.8307 - val_mean_absolute_error: 8.2015

As you can see from the preceding code, the model is trained in small batches of size 32, and 20% of the data is reserved for validation to avoid overfitting. Here, 100 epochs or iterations are run to train the network. Once the training process is completed, information related to the training process is saved in model_one, which can then be used to plot the loss and mean absolute error based on the training and validation data for all epochs:

plot(model_one)

The preceding line of code will return the following output. Let's have a look at the loss and mean absolute error for training and validation data (model_oneplot:

From the preceding plot, we can make the following observations:

  • The mae and loss values decrease for both the training and validation data as the training proceeds.
  • The rate of decrease in errors for the training data reduces after about 60 epochs.

After developing the prediction model, we can assess its performance by evaluating the prediction quality of the model, which we will look at in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset