How to do it...

Now, we can build our first sequential keras model and train it:

  1. Let's start by defining a sequential model:
model_sequential <- keras_model_sequential()
  1. We need to add layers to the model we defined in the preceding code block:
model_sequential %>% 
layer_dense(units = 16,batch_size = ,input_shape = c(784)) %>%
layer_activation('relu') %>%
layer_dense(units = 1)

  1. After adding the layers to our model, we need to compile it:
model_sequential %>% compile(
loss = "mse",
optimizer = optimizer_sgd(),
metrics = list("mean_absolute_error")
)
  1. Now, let's visualize the summary of the model we created:
model_sequential %>% summary()

The summary of the model is as follows:

  1. Now, let's train the model and store the training stats in a variable in order to plot the model's metrics:
history <- model_sequential %>% fit(
x_data,
y_data,
epochs = 30,
batch_size = 128,
validation_split = 0.2
)

# Plotting model metrics
plot(history)

The preceding code generates the following plot:

The preceding plot shows the loss and mean absolute error for the training and validation data.

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

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