Thank you

A big thank you to Leon Jessen for posting his code on github.

Building a simple neural network using Keras and Tensorflow

I have forked his project on github and put his code into an R Notebook so we can run it in class.

Motivation

The following is a minimal example for building your first simple artificial neural network using Keras and TensorFlow for R.

TensorFlow for R by Rstudio lives here.

Gettings started - Install Keras and TensorFlow for R

You can install the Keras for R package from CRAN as follows:

# install.packages("keras")

TensorFlow is the default backend engine. TensorFlow and Keras can be installed as follows:

# library(keras)
# install_keras()

Naturally, we will also need TidyVerse:

# Install from CRAN
# install.packages("tidyverse")

# Or the development version from GitHub
# install.packages("devtools")
# devtools::install_github("hadley/tidyverse")

Once installed, we simply load the libraries

library("keras")
suppressMessages(library("tidyverse"))

Artificial Neural Network Using the Iris Data Set

Right, let’s get to it!

Data

The famous (Fisher’s or Anderson’s) iris data set contains a total of 150 observations of 4 input features Sepal.Length, Sepal.Width, Petal.Length and Petal.Width and 3 output classes setosa versicolor and virginica, with 50 observations in each class. The distributions of the feature values looks like so:

iris %>% as_tibble %>% gather(feature, value, -Species) %>%
  ggplot(aes(x = feature, y = value, fill = Species)) +
  geom_violin(alpha = 0.5, scale = "width") +
  theme_bw()

Our aim is to connect the 4 input features to the correct output class using an artificial neural network. For this task, we have chosen the following simple architecture with one input layer with 4 neurons (one for each feature), one hidden layer with 4 neurons and one output layer with 3 neurons (one for each class), all fully connected:

architecture_visualisation.png

Our artificial neural network will have a total of 35 parameters: 4 for each input neuron connected to the hidden layer, plus an additional 4 for the associated first bias neuron and 3 for each of the hidden neurons connected to the output layer, plus an additional 3 for the associated second bias neuron. I.e. \(4 \times 4+4+4 \ times 3+3=35\)

Prepare data

We start with slightly wrangling the iris data set by renaming and scaling the features and converting character labels to numeric:

set.seed(265509)
nn_dat <- iris %>% as_tibble %>%
  mutate(sepal_length = scale(Sepal.Length),
         sepal_width  = scale(Sepal.Width),
         petal_length = scale(Petal.Length),
         petal_width  = scale(Petal.Width),          
         class_label  = as.numeric(Species) - 1) %>% 
    select(sepal_length, sepal_width, petal_length, petal_width, class_label)

nn_dat %>% head(3)

Then, we create indices for splitting the iris data into a training and a test data set. We set aside 20% of the data for testing:

test_fraction   <- 0.20
n_total_samples <- nrow(nn_dat)
n_train_samples <- ceiling((1 - test_fraction) * n_total_samples)
train_indices   <- sample(n_total_samples, n_train_samples)
n_test_samples  <- n_total_samples - n_train_samples
test_indices    <- setdiff(seq(1, n_train_samples), train_indices)

Based on the indices, we can now create training and test data

x_train <- nn_dat %>% select(-class_label) %>% as.matrix %>% .[train_indices,]
y_train <- nn_dat %>% pull(class_label) %>% .[train_indices] %>% to_categorical(3)
x_test  <- nn_dat %>% select(-class_label) %>% as.matrix %>% .[test_indices,]
y_test  <- nn_dat %>% pull(class_label) %>% .[test_indices] %>% to_categorical(3)

Set Architecture

With the data in place, we now set the architecture of our artificical neural network:

model <- keras_model_sequential()
model %>% 
  layer_dense(units = 4, activation = 'relu', input_shape = 4) %>% 
  layer_dense(units = 3, activation = 'softmax')
model %>% summary
Model: "sequential_2"
_________________________________________________________________________________________________
Layer (type)                               Output Shape                           Param #        
=================================================================================================
dense_5 (Dense)                            (None, 4)                              20             
_________________________________________________________________________________________________
dense_4 (Dense)                            (None, 3)                              15             
=================================================================================================
Total params: 35
Trainable params: 35
Non-trainable params: 0
_________________________________________________________________________________________________

Next, the architecture set in the model needs to be compiled:

model %>% compile(
  loss      = 'categorical_crossentropy',
  optimizer = optimizer_rmsprop(),
  metrics   = c('accuracy')
)

Train the Artificial Neural Network

Lastly we fit the model and save the training progres in the history object:

history <- model %>% fit(
  x = x_train, y = y_train,
  epochs = 200,
  batch_size = 20,
  validation_split = 0
)
Epoch 1/200

1/6 [====>.........................] - ETA: 0s - loss: 1.3146 - accuracy: 0.4500
6/6 [==============================] - 0s 632us/step - loss: 1.3092 - accuracy: 0.3333

6/6 [==============================] - 1s 85ms/step - loss: 1.3092 - accuracy: 0.3333 
Epoch 2/200

1/6 [====>.........................] - ETA: 0s - loss: 1.1826 - accuracy: 0.3500
6/6 [==============================] - 0s 586us/step - loss: 1.2631 - accuracy: 0.3500

6/6 [==============================] - 0s 19ms/step - loss: 1.2631 - accuracy: 0.3500 
Epoch 3/200

1/6 [====>.........................] - ETA: 0s - loss: 1.4383 - accuracy: 0.2000
6/6 [==============================] - 0s 3ms/step - loss: 1.2305 - accuracy: 0.3583

6/6 [==============================] - 0s 23ms/step - loss: 1.2305 - accuracy: 0.3583
Epoch 4/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9543 - accuracy: 0.4500
6/6 [==============================] - 0s 2ms/step - loss: 1.2025 - accuracy: 0.3583

6/6 [==============================] - 0s 22ms/step - loss: 1.2025 - accuracy: 0.3583
Epoch 5/200

1/6 [====>.........................] - ETA: 0s - loss: 1.2216 - accuracy: 0.3500
6/6 [==============================] - 0s 1ms/step - loss: 1.1776 - accuracy: 0.3667

6/6 [==============================] - 0s 20ms/step - loss: 1.1776 - accuracy: 0.3667
Epoch 6/200

1/6 [====>.........................] - ETA: 0s - loss: 1.2356 - accuracy: 0.2000
6/6 [==============================] - 0s 754us/step - loss: 1.1545 - accuracy: 0.3667

6/6 [==============================] - 0s 19ms/step - loss: 1.1545 - accuracy: 0.3667 
Epoch 7/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8686 - accuracy: 0.5000
6/6 [==============================] - 0s 2ms/step - loss: 1.1328 - accuracy: 0.3667

6/6 [==============================] - 0s 22ms/step - loss: 1.1328 - accuracy: 0.3667
Epoch 8/200

1/6 [====>.........................] - ETA: 0s - loss: 1.1982 - accuracy: 0.1500
6/6 [==============================] - 0s 522us/step - loss: 1.1122 - accuracy: 0.3667

6/6 [==============================] - 0s 18ms/step - loss: 1.1122 - accuracy: 0.3667 
Epoch 9/200

1/6 [====>.........................] - ETA: 0s - loss: 1.2572 - accuracy: 0.1500
6/6 [==============================] - 0s 581us/step - loss: 1.0929 - accuracy: 0.3750

6/6 [==============================] - 0s 20ms/step - loss: 1.0929 - accuracy: 0.3750 
Epoch 10/200

1/6 [====>.........................] - ETA: 0s - loss: 1.0138 - accuracy: 0.3500
6/6 [==============================] - 0s 838us/step - loss: 1.0745 - accuracy: 0.3833

6/6 [==============================] - 0s 19ms/step - loss: 1.0745 - accuracy: 0.3833 
Epoch 11/200

1/6 [====>.........................] - ETA: 0s - loss: 1.0590 - accuracy: 0.3000
6/6 [==============================] - 0s 3ms/step - loss: 1.0570 - accuracy: 0.3833

6/6 [==============================] - 0s 23ms/step - loss: 1.0570 - accuracy: 0.3833
Epoch 12/200

1/6 [====>.........................] - ETA: 0s - loss: 1.0460 - accuracy: 0.3000
6/6 [==============================] - 0s 2ms/step - loss: 1.0403 - accuracy: 0.3833

6/6 [==============================] - 0s 23ms/step - loss: 1.0403 - accuracy: 0.3833
Epoch 13/200

1/6 [====>.........................] - ETA: 0s - loss: 1.1162 - accuracy: 0.2500
6/6 [==============================] - 0s 2ms/step - loss: 1.0245 - accuracy: 0.3917

6/6 [==============================] - 0s 21ms/step - loss: 1.0245 - accuracy: 0.3917
Epoch 14/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8707 - accuracy: 0.5000
6/6 [==============================] - 0s 3ms/step - loss: 1.0090 - accuracy: 0.4083

6/6 [==============================] - 0s 23ms/step - loss: 1.0090 - accuracy: 0.4083
Epoch 15/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9713 - accuracy: 0.4000
6/6 [==============================] - 0s 1ms/step - loss: 0.9941 - accuracy: 0.4083

6/6 [==============================] - 0s 20ms/step - loss: 0.9941 - accuracy: 0.4083
Epoch 16/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9151 - accuracy: 0.5000
6/6 [==============================] - 0s 579us/step - loss: 0.9794 - accuracy: 0.4083

6/6 [==============================] - 0s 18ms/step - loss: 0.9794 - accuracy: 0.4083 
Epoch 17/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8932 - accuracy: 0.5000
6/6 [==============================] - 0s 595us/step - loss: 0.9656 - accuracy: 0.4083

6/6 [==============================] - 0s 19ms/step - loss: 0.9656 - accuracy: 0.4083 
Epoch 18/200

1/6 [====>.........................] - ETA: 0s - loss: 1.1059 - accuracy: 0.3000
6/6 [==============================] - 0s 2ms/step - loss: 0.9522 - accuracy: 0.4083

6/6 [==============================] - 0s 22ms/step - loss: 0.9522 - accuracy: 0.4083
Epoch 19/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9085 - accuracy: 0.4500
6/6 [==============================] - 0s 2ms/step - loss: 0.9392 - accuracy: 0.4333

6/6 [==============================] - 0s 21ms/step - loss: 0.9392 - accuracy: 0.4333
Epoch 20/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8883 - accuracy: 0.4500
6/6 [==============================] - 0s 790us/step - loss: 0.9266 - accuracy: 0.4500

6/6 [==============================] - 0s 19ms/step - loss: 0.9266 - accuracy: 0.4500 
Epoch 21/200

1/6 [====>.........................] - ETA: 0s - loss: 1.0031 - accuracy: 0.4500
6/6 [==============================] - 0s 1ms/step - loss: 0.9145 - accuracy: 0.4417

6/6 [==============================] - 0s 20ms/step - loss: 0.9145 - accuracy: 0.4417
Epoch 22/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7275 - accuracy: 0.5500
6/6 [==============================] - 0s 2ms/step - loss: 0.9029 - accuracy: 0.4583

6/6 [==============================] - 0s 22ms/step - loss: 0.9029 - accuracy: 0.4583
Epoch 23/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9503 - accuracy: 0.4000
6/6 [==============================] - 0s 1ms/step - loss: 0.8918 - accuracy: 0.4500

6/6 [==============================] - 0s 21ms/step - loss: 0.8918 - accuracy: 0.4500
Epoch 24/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7148 - accuracy: 0.5000
6/6 [==============================] - 0s 625us/step - loss: 0.8813 - accuracy: 0.4500

6/6 [==============================] - 0s 18ms/step - loss: 0.8813 - accuracy: 0.4500 
Epoch 25/200

1/6 [====>.........................] - ETA: 0s - loss: 1.2577 - accuracy: 0.3000
6/6 [==============================] - 0s 627us/step - loss: 0.8710 - accuracy: 0.4500

6/6 [==============================] - 0s 19ms/step - loss: 0.8710 - accuracy: 0.4500 
Epoch 26/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7393 - accuracy: 0.6500
6/6 [==============================] - 0s 552us/step - loss: 0.8613 - accuracy: 0.4500

6/6 [==============================] - 0s 18ms/step - loss: 0.8613 - accuracy: 0.4500 
Epoch 27/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7891 - accuracy: 0.4500
6/6 [==============================] - 0s 786us/step - loss: 0.8516 - accuracy: 0.4583

6/6 [==============================] - 0s 19ms/step - loss: 0.8516 - accuracy: 0.4583 
Epoch 28/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7014 - accuracy: 0.5000
6/6 [==============================] - 0s 1ms/step - loss: 0.8423 - accuracy: 0.4667

6/6 [==============================] - 0s 21ms/step - loss: 0.8423 - accuracy: 0.4667
Epoch 29/200

1/6 [====>.........................] - ETA: 0s - loss: 1.0145 - accuracy: 0.4000
6/6 [==============================] - 0s 1ms/step - loss: 0.8333 - accuracy: 0.4917

6/6 [==============================] - 0s 20ms/step - loss: 0.8333 - accuracy: 0.4917
Epoch 30/200

1/6 [====>.........................] - ETA: 0s - loss: 0.9247 - accuracy: 0.4500
6/6 [==============================] - 0s 2ms/step - loss: 0.8244 - accuracy: 0.5083

6/6 [==============================] - 0s 21ms/step - loss: 0.8244 - accuracy: 0.5083
Epoch 31/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6738 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.8158 - accuracy: 0.5083

6/6 [==============================] - 0s 20ms/step - loss: 0.8158 - accuracy: 0.5083
Epoch 32/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8393 - accuracy: 0.5500
6/6 [==============================] - 0s 629us/step - loss: 0.8075 - accuracy: 0.5083

6/6 [==============================] - 0s 19ms/step - loss: 0.8075 - accuracy: 0.5083 
Epoch 33/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6671 - accuracy: 0.5000
6/6 [==============================] - 0s 754us/step - loss: 0.7995 - accuracy: 0.5000

6/6 [==============================] - 0s 19ms/step - loss: 0.7995 - accuracy: 0.5000 
Epoch 34/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8134 - accuracy: 0.4500
6/6 [==============================] - 0s 2ms/step - loss: 0.7917 - accuracy: 0.4917

6/6 [==============================] - 0s 22ms/step - loss: 0.7917 - accuracy: 0.4917
Epoch 35/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6892 - accuracy: 0.5500
6/6 [==============================] - 0s 3ms/step - loss: 0.7845 - accuracy: 0.5083

6/6 [==============================] - 0s 23ms/step - loss: 0.7845 - accuracy: 0.5083
Epoch 36/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6879 - accuracy: 0.6000
6/6 [==============================] - 0s 585us/step - loss: 0.7772 - accuracy: 0.5333

6/6 [==============================] - 0s 19ms/step - loss: 0.7772 - accuracy: 0.5333 
Epoch 37/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6998 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.7703 - accuracy: 0.5500

6/6 [==============================] - 0s 23ms/step - loss: 0.7703 - accuracy: 0.5500
Epoch 38/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6709 - accuracy: 0.7000
6/6 [==============================] - 0s 2ms/step - loss: 0.7634 - accuracy: 0.5500

6/6 [==============================] - 0s 22ms/step - loss: 0.7634 - accuracy: 0.5500
Epoch 39/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7880 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.7567 - accuracy: 0.5750

6/6 [==============================] - 0s 22ms/step - loss: 0.7567 - accuracy: 0.5750
Epoch 40/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7314 - accuracy: 0.7000
6/6 [==============================] - 0s 617us/step - loss: 0.7501 - accuracy: 0.5833

6/6 [==============================] - 0s 19ms/step - loss: 0.7501 - accuracy: 0.5833 
Epoch 41/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7269 - accuracy: 0.7500
6/6 [==============================] - 0s 618us/step - loss: 0.7439 - accuracy: 0.5833

6/6 [==============================] - 0s 19ms/step - loss: 0.7439 - accuracy: 0.5833 
Epoch 42/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7133 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.7378 - accuracy: 0.5833

6/6 [==============================] - 0s 21ms/step - loss: 0.7378 - accuracy: 0.5833
Epoch 43/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6314 - accuracy: 0.5500
6/6 [==============================] - 0s 702us/step - loss: 0.7320 - accuracy: 0.5833

6/6 [==============================] - 0s 19ms/step - loss: 0.7320 - accuracy: 0.5833 
Epoch 44/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6208 - accuracy: 0.5500
6/6 [==============================] - 0s 2ms/step - loss: 0.7264 - accuracy: 0.6000

6/6 [==============================] - 0s 22ms/step - loss: 0.7264 - accuracy: 0.6000
Epoch 45/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4508 - accuracy: 0.7000
6/6 [==============================] - 0s 847us/step - loss: 0.7211 - accuracy: 0.5917

6/6 [==============================] - 0s 21ms/step - loss: 0.7211 - accuracy: 0.5917 
Epoch 46/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7018 - accuracy: 0.6500
6/6 [==============================] - 0s 617us/step - loss: 0.7158 - accuracy: 0.5917

6/6 [==============================] - 0s 19ms/step - loss: 0.7158 - accuracy: 0.5917 
Epoch 47/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6888 - accuracy: 0.5500
6/6 [==============================] - 0s 592us/step - loss: 0.7108 - accuracy: 0.6000

6/6 [==============================] - 0s 19ms/step - loss: 0.7108 - accuracy: 0.6000 
Epoch 48/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7136 - accuracy: 0.6000
6/6 [==============================] - 0s 728us/step - loss: 0.7059 - accuracy: 0.6167

6/6 [==============================] - 0s 19ms/step - loss: 0.7059 - accuracy: 0.6167 
Epoch 49/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7264 - accuracy: 0.6000
6/6 [==============================] - 0s 761us/step - loss: 0.7011 - accuracy: 0.6250

6/6 [==============================] - 0s 19ms/step - loss: 0.7011 - accuracy: 0.6250 
Epoch 50/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7306 - accuracy: 0.7500
6/6 [==============================] - 0s 783us/step - loss: 0.6966 - accuracy: 0.6333

6/6 [==============================] - 0s 19ms/step - loss: 0.6966 - accuracy: 0.6333 
Epoch 51/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4879 - accuracy: 0.7500
6/6 [==============================] - 0s 835us/step - loss: 0.6925 - accuracy: 0.6333

6/6 [==============================] - 0s 19ms/step - loss: 0.6925 - accuracy: 0.6333 
Epoch 52/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6134 - accuracy: 0.7500
6/6 [==============================] - 0s 2ms/step - loss: 0.6882 - accuracy: 0.6417

6/6 [==============================] - 0s 22ms/step - loss: 0.6882 - accuracy: 0.6417
Epoch 53/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5804 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.6841 - accuracy: 0.6417

6/6 [==============================] - 0s 20ms/step - loss: 0.6841 - accuracy: 0.6417
Epoch 54/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5657 - accuracy: 0.8000
6/6 [==============================] - 0s 3ms/step - loss: 0.6803 - accuracy: 0.6583

6/6 [==============================] - 0s 24ms/step - loss: 0.6803 - accuracy: 0.6583
Epoch 55/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8458 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.6765 - accuracy: 0.6583

6/6 [==============================] - 0s 21ms/step - loss: 0.6765 - accuracy: 0.6583
Epoch 56/200

1/6 [====>.........................] - ETA: 0s - loss: 0.8174 - accuracy: 0.5500
6/6 [==============================] - 0s 597us/step - loss: 0.6729 - accuracy: 0.6583

6/6 [==============================] - 0s 18ms/step - loss: 0.6729 - accuracy: 0.6583 
Epoch 57/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6018 - accuracy: 0.5000
6/6 [==============================] - 0s 695us/step - loss: 0.6695 - accuracy: 0.6583

6/6 [==============================] - 0s 19ms/step - loss: 0.6695 - accuracy: 0.6583 
Epoch 58/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6955 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.6661 - accuracy: 0.6583

6/6 [==============================] - 0s 21ms/step - loss: 0.6661 - accuracy: 0.6583
Epoch 59/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7480 - accuracy: 0.8000
6/6 [==============================] - 0s 649us/step - loss: 0.6630 - accuracy: 0.6583

6/6 [==============================] - 0s 19ms/step - loss: 0.6630 - accuracy: 0.6583 
Epoch 60/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6712 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.6598 - accuracy: 0.6583

6/6 [==============================] - 0s 21ms/step - loss: 0.6598 - accuracy: 0.6583
Epoch 61/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7638 - accuracy: 0.7000
6/6 [==============================] - 0s 2ms/step - loss: 0.6568 - accuracy: 0.6583

6/6 [==============================] - 0s 22ms/step - loss: 0.6568 - accuracy: 0.6583
Epoch 62/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7733 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.6539 - accuracy: 0.6583

6/6 [==============================] - 0s 21ms/step - loss: 0.6539 - accuracy: 0.6583
Epoch 63/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7415 - accuracy: 0.7500
6/6 [==============================] - 0s 3ms/step - loss: 0.6510 - accuracy: 0.6583

6/6 [==============================] - 0s 23ms/step - loss: 0.6510 - accuracy: 0.6583
Epoch 64/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6543 - accuracy: 0.7000
6/6 [==============================] - 0s 579us/step - loss: 0.6482 - accuracy: 0.6583

6/6 [==============================] - 0s 18ms/step - loss: 0.6482 - accuracy: 0.6583 
Epoch 65/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6206 - accuracy: 0.6500
6/6 [==============================] - 0s 624us/step - loss: 0.6454 - accuracy: 0.6583

6/6 [==============================] - 0s 19ms/step - loss: 0.6454 - accuracy: 0.6583 
Epoch 66/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6605 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.6427 - accuracy: 0.6583

6/6 [==============================] - 0s 22ms/step - loss: 0.6427 - accuracy: 0.6583
Epoch 67/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5182 - accuracy: 0.6500
6/6 [==============================] - 0s 2ms/step - loss: 0.6403 - accuracy: 0.6583

6/6 [==============================] - 0s 22ms/step - loss: 0.6403 - accuracy: 0.6583
Epoch 68/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6439 - accuracy: 0.8000
6/6 [==============================] - 0s 1ms/step - loss: 0.6379 - accuracy: 0.6583

6/6 [==============================] - 0s 23ms/step - loss: 0.6379 - accuracy: 0.6583
Epoch 69/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5915 - accuracy: 0.7500
6/6 [==============================] - 0s 2ms/step - loss: 0.6357 - accuracy: 0.6667

6/6 [==============================] - 0s 22ms/step - loss: 0.6357 - accuracy: 0.6667
Epoch 70/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6438 - accuracy: 0.8000
6/6 [==============================] - 0s 1ms/step - loss: 0.6336 - accuracy: 0.6667

6/6 [==============================] - 0s 21ms/step - loss: 0.6336 - accuracy: 0.6667
Epoch 71/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5953 - accuracy: 0.7500
6/6 [==============================] - 0s 1ms/step - loss: 0.6316 - accuracy: 0.6667

6/6 [==============================] - 0s 21ms/step - loss: 0.6316 - accuracy: 0.6667
Epoch 72/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7936 - accuracy: 0.5500
6/6 [==============================] - 0s 585us/step - loss: 0.6296 - accuracy: 0.6667

6/6 [==============================] - 0s 19ms/step - loss: 0.6296 - accuracy: 0.6667 
Epoch 73/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5576 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.6275 - accuracy: 0.6667

6/6 [==============================] - 0s 21ms/step - loss: 0.6275 - accuracy: 0.6667
Epoch 74/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5583 - accuracy: 0.6500
6/6 [==============================] - 0s 721us/step - loss: 0.6255 - accuracy: 0.6833

6/6 [==============================] - 0s 19ms/step - loss: 0.6255 - accuracy: 0.6833 
Epoch 75/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7650 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.6236 - accuracy: 0.6833

6/6 [==============================] - 0s 20ms/step - loss: 0.6236 - accuracy: 0.6833
Epoch 76/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5352 - accuracy: 0.8000
6/6 [==============================] - 0s 1ms/step - loss: 0.6217 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.6217 - accuracy: 0.6917
Epoch 77/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5358 - accuracy: 0.8500
6/6 [==============================] - 0s 1ms/step - loss: 0.6198 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.6198 - accuracy: 0.6917
Epoch 78/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6879 - accuracy: 0.5500
6/6 [==============================] - 0s 713us/step - loss: 0.6180 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.6180 - accuracy: 0.6917 
Epoch 79/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5994 - accuracy: 0.6000
6/6 [==============================] - 0s 3ms/step - loss: 0.6164 - accuracy: 0.6917

6/6 [==============================] - 0s 23ms/step - loss: 0.6164 - accuracy: 0.6917
Epoch 80/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7281 - accuracy: 0.6000
6/6 [==============================] - 0s 740us/step - loss: 0.6147 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.6147 - accuracy: 0.6917 
Epoch 81/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5808 - accuracy: 0.7000
6/6 [==============================] - 0s 648us/step - loss: 0.6131 - accuracy: 0.6917

6/6 [==============================] - 0s 47ms/step - loss: 0.6131 - accuracy: 0.6917 
Epoch 82/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5839 - accuracy: 0.7000
6/6 [==============================] - 0s 2ms/step - loss: 0.6115 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.6115 - accuracy: 0.6917
Epoch 83/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6340 - accuracy: 0.6000
6/6 [==============================] - 0s 532us/step - loss: 0.6100 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.6100 - accuracy: 0.6917 
Epoch 84/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6165 - accuracy: 0.7500
6/6 [==============================] - 0s 3ms/step - loss: 0.6085 - accuracy: 0.6917

6/6 [==============================] - 0s 23ms/step - loss: 0.6085 - accuracy: 0.6917
Epoch 85/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6126 - accuracy: 0.7500
6/6 [==============================] - 0s 1ms/step - loss: 0.6070 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.6070 - accuracy: 0.6917
Epoch 86/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5778 - accuracy: 0.7000
6/6 [==============================] - 0s 777us/step - loss: 0.6056 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.6056 - accuracy: 0.6917 
Epoch 87/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5722 - accuracy: 0.7500
6/6 [==============================] - 0s 588us/step - loss: 0.6042 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.6042 - accuracy: 0.6917 
Epoch 88/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7331 - accuracy: 0.7500
6/6 [==============================] - 0s 2ms/step - loss: 0.6029 - accuracy: 0.6917

6/6 [==============================] - 0s 23ms/step - loss: 0.6029 - accuracy: 0.6917
Epoch 89/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5736 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.6015 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.6015 - accuracy: 0.6917
Epoch 90/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5786 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.6002 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.6002 - accuracy: 0.6917
Epoch 91/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6256 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.5988 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5988 - accuracy: 0.6917
Epoch 92/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6103 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.5975 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5975 - accuracy: 0.6917
Epoch 93/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7444 - accuracy: 0.6000
6/6 [==============================] - 0s 1ms/step - loss: 0.5963 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5963 - accuracy: 0.6917
Epoch 94/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6956 - accuracy: 0.6500
6/6 [==============================] - 0s 717us/step - loss: 0.5950 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5950 - accuracy: 0.6917 
Epoch 95/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5259 - accuracy: 0.7000
6/6 [==============================] - 0s 700us/step - loss: 0.5938 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5938 - accuracy: 0.6917 
Epoch 96/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7107 - accuracy: 0.5000
6/6 [==============================] - 0s 1ms/step - loss: 0.5926 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5926 - accuracy: 0.6917
Epoch 97/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4441 - accuracy: 0.7000
6/6 [==============================] - 0s 902us/step - loss: 0.5914 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5914 - accuracy: 0.6917 
Epoch 98/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5224 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.5903 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5903 - accuracy: 0.6917
Epoch 99/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6222 - accuracy: 0.8500
6/6 [==============================] - 0s 962us/step - loss: 0.5892 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5892 - accuracy: 0.6917 
Epoch 100/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7337 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.5881 - accuracy: 0.6917

6/6 [==============================] - 0s 23ms/step - loss: 0.5881 - accuracy: 0.6917
Epoch 101/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5195 - accuracy: 0.7000
6/6 [==============================] - 0s 718us/step - loss: 0.5871 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5871 - accuracy: 0.6917 
Epoch 102/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6514 - accuracy: 0.6000
6/6 [==============================] - 0s 656us/step - loss: 0.5861 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5861 - accuracy: 0.6917 
Epoch 103/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5375 - accuracy: 0.8500
6/6 [==============================] - 0s 596us/step - loss: 0.5851 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5851 - accuracy: 0.6917 
Epoch 104/200

1/6 [====>.........................] - ETA: 0s - loss: 0.3722 - accuracy: 0.9000
6/6 [==============================] - 0s 586us/step - loss: 0.5841 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5841 - accuracy: 0.6917 
Epoch 105/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6097 - accuracy: 0.6000
6/6 [==============================] - 0s 1ms/step - loss: 0.5832 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5832 - accuracy: 0.6917
Epoch 106/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6803 - accuracy: 0.6500
6/6 [==============================] - 0s 944us/step - loss: 0.5822 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5822 - accuracy: 0.6917 
Epoch 107/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6398 - accuracy: 0.6500
6/6 [==============================] - 0s 861us/step - loss: 0.5814 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5814 - accuracy: 0.6917 
Epoch 108/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5460 - accuracy: 0.7500
6/6 [==============================] - 0s 1ms/step - loss: 0.5803 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5803 - accuracy: 0.6917
Epoch 109/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5922 - accuracy: 0.7000
6/6 [==============================] - 0s 805us/step - loss: 0.5794 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5794 - accuracy: 0.6917 
Epoch 110/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6299 - accuracy: 0.7000
6/6 [==============================] - 0s 1ms/step - loss: 0.5784 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5784 - accuracy: 0.6917
Epoch 111/200

1/6 [====>.........................] - ETA: 0s - loss: 0.7738 - accuracy: 0.5000
6/6 [==============================] - 0s 678us/step - loss: 0.5775 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5775 - accuracy: 0.6917 
Epoch 112/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6669 - accuracy: 0.7000
6/6 [==============================] - 0s 587us/step - loss: 0.5765 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.5765 - accuracy: 0.6917 
Epoch 113/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4115 - accuracy: 0.8500
6/6 [==============================] - 0s 2ms/step - loss: 0.5756 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5756 - accuracy: 0.6917
Epoch 114/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5871 - accuracy: 0.7000
6/6 [==============================] - 0s 697us/step - loss: 0.5746 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5746 - accuracy: 0.6917 
Epoch 115/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5014 - accuracy: 0.7500
6/6 [==============================] - 0s 2ms/step - loss: 0.5737 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5737 - accuracy: 0.6917
Epoch 116/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6300 - accuracy: 0.6500
6/6 [==============================] - 0s 657us/step - loss: 0.5727 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5727 - accuracy: 0.6917 
Epoch 117/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4466 - accuracy: 0.8500
6/6 [==============================] - 0s 3ms/step - loss: 0.5718 - accuracy: 0.6917

6/6 [==============================] - 0s 24ms/step - loss: 0.5718 - accuracy: 0.6917
Epoch 118/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5294 - accuracy: 0.8000
6/6 [==============================] - 0s 2ms/step - loss: 0.5710 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5710 - accuracy: 0.6917
Epoch 119/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5448 - accuracy: 0.7000
6/6 [==============================] - 0s 702us/step - loss: 0.5700 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5700 - accuracy: 0.6917 
Epoch 120/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6877 - accuracy: 0.7500
6/6 [==============================] - 0s 584us/step - loss: 0.5691 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.5691 - accuracy: 0.6917 
Epoch 121/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6489 - accuracy: 0.7500
6/6 [==============================] - 0s 765us/step - loss: 0.5682 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5682 - accuracy: 0.6917 
Epoch 122/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5650 - accuracy: 0.5500
6/6 [==============================] - 0s 1ms/step - loss: 0.5674 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5674 - accuracy: 0.6917
Epoch 123/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6406 - accuracy: 0.5500
6/6 [==============================] - 0s 687us/step - loss: 0.5665 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5665 - accuracy: 0.6917 
Epoch 124/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6143 - accuracy: 0.7000
6/6 [==============================] - 0s 989us/step - loss: 0.5655 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5655 - accuracy: 0.6917 
Epoch 125/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6083 - accuracy: 0.7500
6/6 [==============================] - 0s 848us/step - loss: 0.5646 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5646 - accuracy: 0.6917 
Epoch 126/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6228 - accuracy: 0.6500
6/6 [==============================] - 0s 588us/step - loss: 0.5637 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5637 - accuracy: 0.6917 
Epoch 127/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5465 - accuracy: 0.6500
6/6 [==============================] - 0s 612us/step - loss: 0.5628 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5628 - accuracy: 0.6917 
Epoch 128/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5298 - accuracy: 0.7500
6/6 [==============================] - 0s 570us/step - loss: 0.5619 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5619 - accuracy: 0.6917 
Epoch 129/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4281 - accuracy: 0.8500
6/6 [==============================] - 0s 935us/step - loss: 0.5611 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5611 - accuracy: 0.6917 
Epoch 130/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6695 - accuracy: 0.5500
6/6 [==============================] - 0s 601us/step - loss: 0.5601 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5601 - accuracy: 0.6917 
Epoch 131/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5811 - accuracy: 0.6500
6/6 [==============================] - 0s 962us/step - loss: 0.5593 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5593 - accuracy: 0.6917 
Epoch 132/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6018 - accuracy: 0.7500
6/6 [==============================] - 0s 689us/step - loss: 0.5584 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5584 - accuracy: 0.6917 
Epoch 133/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6543 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.5575 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5575 - accuracy: 0.6917
Epoch 134/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4383 - accuracy: 0.8000
6/6 [==============================] - 0s 693us/step - loss: 0.5565 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5565 - accuracy: 0.6917 
Epoch 135/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6316 - accuracy: 0.7500
6/6 [==============================] - 0s 974us/step - loss: 0.5556 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5556 - accuracy: 0.6917 
Epoch 136/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5152 - accuracy: 0.8000
6/6 [==============================] - 0s 623us/step - loss: 0.5547 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5547 - accuracy: 0.6917 
Epoch 137/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6035 - accuracy: 0.6500
6/6 [==============================] - 0s 615us/step - loss: 0.5538 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5538 - accuracy: 0.6917 
Epoch 138/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5472 - accuracy: 0.6000
6/6 [==============================] - 0s 1ms/step - loss: 0.5529 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5529 - accuracy: 0.6917
Epoch 139/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6686 - accuracy: 0.5000
6/6 [==============================] - 0s 809us/step - loss: 0.5520 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5520 - accuracy: 0.6917 
Epoch 140/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5201 - accuracy: 0.5000
6/6 [==============================] - 0s 1ms/step - loss: 0.5511 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5511 - accuracy: 0.6917
Epoch 141/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6928 - accuracy: 0.6000
6/6 [==============================] - 0s 720us/step - loss: 0.5501 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5501 - accuracy: 0.6917 
Epoch 142/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5260 - accuracy: 0.8500
6/6 [==============================] - 0s 1ms/step - loss: 0.5494 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5494 - accuracy: 0.6917
Epoch 143/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6178 - accuracy: 0.6000
6/6 [==============================] - 0s 737us/step - loss: 0.5484 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5484 - accuracy: 0.6917 
Epoch 144/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4089 - accuracy: 0.7000
6/6 [==============================] - 0s 668us/step - loss: 0.5475 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5475 - accuracy: 0.6917 
Epoch 145/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5860 - accuracy: 0.5500
6/6 [==============================] - 0s 610us/step - loss: 0.5465 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5465 - accuracy: 0.6917 
Epoch 146/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5515 - accuracy: 0.7500
6/6 [==============================] - 0s 675us/step - loss: 0.5456 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5456 - accuracy: 0.6917 
Epoch 147/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5169 - accuracy: 0.7500
6/6 [==============================] - 0s 654us/step - loss: 0.5446 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5446 - accuracy: 0.6917 
Epoch 148/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5611 - accuracy: 0.7000
6/6 [==============================] - 0s 598us/step - loss: 0.5436 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5436 - accuracy: 0.6917 
Epoch 149/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4876 - accuracy: 0.7000
6/6 [==============================] - 0s 838us/step - loss: 0.5427 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5427 - accuracy: 0.6917 
Epoch 150/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5597 - accuracy: 0.6500
6/6 [==============================] - 0s 1ms/step - loss: 0.5418 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5418 - accuracy: 0.6917
Epoch 151/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6531 - accuracy: 0.6500
6/6 [==============================] - 0s 904us/step - loss: 0.5408 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5408 - accuracy: 0.6917 
Epoch 152/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4758 - accuracy: 0.7500
6/6 [==============================] - 0s 804us/step - loss: 0.5399 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5399 - accuracy: 0.6917 
Epoch 153/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6072 - accuracy: 0.5500
6/6 [==============================] - 0s 645us/step - loss: 0.5389 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5389 - accuracy: 0.6917 
Epoch 154/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5891 - accuracy: 0.7000
6/6 [==============================] - 0s 605us/step - loss: 0.5379 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.5379 - accuracy: 0.6917 
Epoch 155/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5705 - accuracy: 0.6000
6/6 [==============================] - 0s 2ms/step - loss: 0.5368 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5368 - accuracy: 0.6917
Epoch 156/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5169 - accuracy: 0.7000
6/6 [==============================] - 0s 830us/step - loss: 0.5357 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5357 - accuracy: 0.6917 
Epoch 157/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4144 - accuracy: 0.7500
6/6 [==============================] - 0s 926us/step - loss: 0.5346 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5346 - accuracy: 0.6917 
Epoch 158/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5302 - accuracy: 0.6000
6/6 [==============================] - 0s 677us/step - loss: 0.5336 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5336 - accuracy: 0.6917 
Epoch 159/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5873 - accuracy: 0.6500
6/6 [==============================] - 0s 713us/step - loss: 0.5325 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5325 - accuracy: 0.6917 
Epoch 160/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5733 - accuracy: 0.7500
6/6 [==============================] - 0s 598us/step - loss: 0.5314 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5314 - accuracy: 0.6917 
Epoch 161/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4812 - accuracy: 0.7000
6/6 [==============================] - 0s 721us/step - loss: 0.5303 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5303 - accuracy: 0.6917 
Epoch 162/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6660 - accuracy: 0.5500
6/6 [==============================] - 0s 591us/step - loss: 0.5292 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.5292 - accuracy: 0.6917 
Epoch 163/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5114 - accuracy: 0.7000
6/6 [==============================] - 0s 579us/step - loss: 0.5281 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5281 - accuracy: 0.6917 
Epoch 164/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6130 - accuracy: 0.6000
6/6 [==============================] - 0s 597us/step - loss: 0.5270 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5270 - accuracy: 0.6917 
Epoch 165/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5206 - accuracy: 0.6500
6/6 [==============================] - 0s 814us/step - loss: 0.5259 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5259 - accuracy: 0.6917 
Epoch 166/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5998 - accuracy: 0.7500
6/6 [==============================] - 0s 1ms/step - loss: 0.5248 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5248 - accuracy: 0.6917
Epoch 167/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5556 - accuracy: 0.5500
6/6 [==============================] - 0s 840us/step - loss: 0.5236 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5236 - accuracy: 0.6917 
Epoch 168/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4537 - accuracy: 0.6000
6/6 [==============================] - 0s 744us/step - loss: 0.5224 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5224 - accuracy: 0.6917 
Epoch 169/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5130 - accuracy: 0.7000
6/6 [==============================] - 0s 2ms/step - loss: 0.5213 - accuracy: 0.6917

6/6 [==============================] - 0s 22ms/step - loss: 0.5213 - accuracy: 0.6917
Epoch 170/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5373 - accuracy: 0.6000
6/6 [==============================] - 0s 678us/step - loss: 0.5201 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5201 - accuracy: 0.6917 
Epoch 171/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4222 - accuracy: 0.7500
6/6 [==============================] - 0s 568us/step - loss: 0.5189 - accuracy: 0.6917

6/6 [==============================] - 0s 43ms/step - loss: 0.5189 - accuracy: 0.6917 
Epoch 172/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5436 - accuracy: 0.7000
6/6 [==============================] - 0s 3ms/step - loss: 0.5178 - accuracy: 0.6917

6/6 [==============================] - 0s 23ms/step - loss: 0.5178 - accuracy: 0.6917
Epoch 173/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5871 - accuracy: 0.6000
6/6 [==============================] - 0s 888us/step - loss: 0.5166 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.5166 - accuracy: 0.6917 
Epoch 174/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5113 - accuracy: 0.7000
6/6 [==============================] - 0s 658us/step - loss: 0.5154 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5154 - accuracy: 0.6917 
Epoch 175/200

1/6 [====>.........................] - ETA: 0s - loss: 0.3877 - accuracy: 0.8500
6/6 [==============================] - 0s 757us/step - loss: 0.5142 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5142 - accuracy: 0.6917 
Epoch 176/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5053 - accuracy: 0.6000
6/6 [==============================] - 0s 839us/step - loss: 0.5130 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5130 - accuracy: 0.6917 
Epoch 177/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4341 - accuracy: 0.8000
6/6 [==============================] - 0s 634us/step - loss: 0.5116 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5116 - accuracy: 0.6917 
Epoch 178/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4135 - accuracy: 0.7000
6/6 [==============================] - 0s 603us/step - loss: 0.5103 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.5103 - accuracy: 0.6917 
Epoch 179/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4641 - accuracy: 0.6500
6/6 [==============================] - 0s 563us/step - loss: 0.5091 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5091 - accuracy: 0.6917 
Epoch 180/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4914 - accuracy: 0.7500
6/6 [==============================] - 0s 1ms/step - loss: 0.5077 - accuracy: 0.6917

6/6 [==============================] - 0s 21ms/step - loss: 0.5077 - accuracy: 0.6917
Epoch 181/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4681 - accuracy: 0.6500
6/6 [==============================] - 0s 572us/step - loss: 0.5065 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5065 - accuracy: 0.6917 
Epoch 182/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4002 - accuracy: 0.7000
6/6 [==============================] - 0s 738us/step - loss: 0.5053 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5053 - accuracy: 0.6917 
Epoch 183/200

1/6 [====>.........................] - ETA: 0s - loss: 0.3638 - accuracy: 0.8500
6/6 [==============================] - 0s 618us/step - loss: 0.5040 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5040 - accuracy: 0.6917 
Epoch 184/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4062 - accuracy: 0.8500
6/6 [==============================] - 0s 644us/step - loss: 0.5029 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5029 - accuracy: 0.6917 
Epoch 185/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5250 - accuracy: 0.6000
6/6 [==============================] - 0s 662us/step - loss: 0.5017 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5017 - accuracy: 0.6917 
Epoch 186/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6363 - accuracy: 0.5500
6/6 [==============================] - 0s 654us/step - loss: 0.5003 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.5003 - accuracy: 0.6917 
Epoch 187/200

1/6 [====>.........................] - ETA: 0s - loss: 0.3830 - accuracy: 0.7500
6/6 [==============================] - 0s 555us/step - loss: 0.4990 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.4990 - accuracy: 0.6917 
Epoch 188/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5892 - accuracy: 0.6000
6/6 [==============================] - 0s 1ms/step - loss: 0.4976 - accuracy: 0.6917

6/6 [==============================] - 0s 20ms/step - loss: 0.4976 - accuracy: 0.6917
Epoch 189/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4722 - accuracy: 0.7500
6/6 [==============================] - 0s 628us/step - loss: 0.4962 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4962 - accuracy: 0.6917 
Epoch 190/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4150 - accuracy: 0.8000
6/6 [==============================] - 0s 592us/step - loss: 0.4948 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4948 - accuracy: 0.6917 
Epoch 191/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4167 - accuracy: 0.8000
6/6 [==============================] - 0s 858us/step - loss: 0.4933 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4933 - accuracy: 0.6917 
Epoch 192/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5952 - accuracy: 0.6000
6/6 [==============================] - 0s 672us/step - loss: 0.4918 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4918 - accuracy: 0.6917 
Epoch 193/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4614 - accuracy: 0.7500
6/6 [==============================] - 0s 577us/step - loss: 0.4901 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4901 - accuracy: 0.6917 
Epoch 194/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6146 - accuracy: 0.6000
6/6 [==============================] - 0s 625us/step - loss: 0.4885 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.4885 - accuracy: 0.6917 
Epoch 195/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5188 - accuracy: 0.6500
6/6 [==============================] - 0s 702us/step - loss: 0.4870 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4870 - accuracy: 0.6917 
Epoch 196/200

1/6 [====>.........................] - ETA: 0s - loss: 0.4562 - accuracy: 0.7500
6/6 [==============================] - 0s 615us/step - loss: 0.4854 - accuracy: 0.6917

6/6 [==============================] - 0s 18ms/step - loss: 0.4854 - accuracy: 0.6917 
Epoch 197/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5204 - accuracy: 0.6500
6/6 [==============================] - 0s 683us/step - loss: 0.4839 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4839 - accuracy: 0.6917 
Epoch 198/200

1/6 [====>.........................] - ETA: 0s - loss: 0.3824 - accuracy: 0.7500
6/6 [==============================] - 0s 603us/step - loss: 0.4825 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4825 - accuracy: 0.6917 
Epoch 199/200

1/6 [====>.........................] - ETA: 0s - loss: 0.5074 - accuracy: 0.6000
6/6 [==============================] - 0s 859us/step - loss: 0.4811 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4811 - accuracy: 0.6917 
Epoch 200/200

1/6 [====>.........................] - ETA: 0s - loss: 0.6141 - accuracy: 0.5500
6/6 [==============================] - 0s 657us/step - loss: 0.4797 - accuracy: 0.6917

6/6 [==============================] - 0s 19ms/step - loss: 0.4797 - accuracy: 0.6917 
plot(history) +
  ggtitle("Training a neural network based classifier on the iris data set") +
  theme_bw()

Evaluate Network Performance

The final performance can be obtained like so:

perf <- model %>% evaluate(x_test, y_test)

1/1 [==============================] - 0s 10us/step - loss: 0.3088 - accuracy: 0.8500

1/1 [==============================] - 0s 220us/step - loss: 0.3088 - accuracy: 0.8500
print(perf)
     loss  accuracy 
0.3087631 0.8500000 
classes <- iris %>% as_tibble %>% pull(Species) %>% unique
y_pred  <- model %>% predict_classes(x_test)
y_true  <- nn_dat %>% pull(class_label) %>% .[test_indices]

tibble(y_true = classes[y_true + 1], y_pred = classes[y_pred + 1],
       Correct = ifelse(y_true == y_pred, "Yes", "No") %>% factor) %>% 
  ggplot(aes(x = y_true, y = y_pred, colour = Correct)) +
  geom_jitter() +
  theme_bw() +
  ggtitle(label = "Classification Performance of Artificial Neural Network",
          subtitle = str_c("Accuracy = ",round(perf[2],3)*100,"%")) +
  xlab(label = "True iris class") +
  ylab(label = "Predicted iris class")

library(gmodels)

CrossTable(y_pred, y_true,
           prop.chisq = FALSE, prop.t = FALSE, prop.r = FALSE,
           dnn = c('predicted', 'actual'))

 
   Cell Contents
|-------------------------|
|                       N |
|           N / Col Total |
|-------------------------|

 
Total Observations in Table:  20 

 
             | actual 
   predicted |         0 |         1 |         2 | Row Total | 
-------------|-----------|-----------|-----------|-----------|
           0 |        12 |         0 |         0 |        12 | 
             |     1.000 |     0.000 |     0.000 |           | 
-------------|-----------|-----------|-----------|-----------|
           1 |         0 |         5 |         3 |         8 | 
             |     0.000 |     1.000 |     1.000 |           | 
-------------|-----------|-----------|-----------|-----------|
Column Total |        12 |         5 |         3 |        20 | 
             |     0.600 |     0.250 |     0.150 |           | 
-------------|-----------|-----------|-----------|-----------|

 

Conclusion

I hope this illustrated just how easy it is to get started building artificial neural network using Keras and TensorFlow in R. With relative ease, we created a 3-class predictor with an accuracy of 100%. This was a basic minimal example. The network can be expanded to create Deep Learning networks and also the entire TensorFlow API is available.

Enjoy and Happy Learning!

Leon

Thanks again Leon, this was awsome!!!

LS0tCnRpdGxlOiAiQnVpbGRpbmcgYSBzaW1wbGUgbmV1cmFsIG5ldHdvcmsgdXNpbmcgS2VyYXMgYW5kIFRlbnNvcmZsb3ciCm91dHB1dDoKICBodG1sX25vdGVib29rOiBkZWZhdWx0CiAgcGRmX2RvY3VtZW50OiBkZWZhdWx0CiAgd29yZF9kb2N1bWVudDogZGVmYXVsdAogIGh0bWxfZG9jdW1lbnQ6CiAgICBkZl9wcmludDogcGFnZWQKLS0tCgpUaGFuayB5b3UKLS0tLS0tLS0tLQoKQSBiaWcgdGhhbmsgeW91IHRvIExlb24gSmVzc2VuIGZvciBwb3N0aW5nIGhpcyBjb2RlIG9uIGdpdGh1Yi4KCltCdWlsZGluZyBhIHNpbXBsZSBuZXVyYWwgbmV0d29yayB1c2luZyBL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