We will now obtain loss and accuracy values for the training data and then create a confusion matrix using the following code:
# Model evaluation
model %>% evaluate(trainx, trainLabels)
OUTPUT
12/12 [==============================] - 0s 87us/step
$loss
[1] 0.055556579307
$acc
[1] 1
# Confusion matrix
pred <- model %>% predict_classes(trainx)
table(Predicted=pred, Actual=trainy)
OUTPUT
Actual
Predicted 0 1 2
0 3 0 0
1 0 3 0
2 0 0 3
As you can see from the preceding output, the loss and accuracy values are 0.056 and 1 respectively. The confusion matrix based on the training data indicates that all nine images are correctly classified into three categories, and therefore the resulting accuracy is 1.