In this recipe, we will look into the performance of the trained CNN on test images using a confusion matrix and plots.
- Get the
actual
ortrue
class labels of test images:
test_true_class <- c(unlist(images.lab.test))
- Get the predicted class labels of test images. Remember to add
1
to each class label, as the starting index of TensorFlow (the same as Python) is 0 and that of R is1
:
test_pred_class <- y_pred_cls$eval(feed_dict = dict( x = test_data$images, y_true = test_data$labels, keep_prob = 1.0)) test_pred_class <- test_pred_class + 1
- Generate the confusion matrix with rows as true labels and columns as predicted labels:
table(actual = test_true_class, predicted = test_pred_class)
- Generate a plot of the
confusion
matrix:
confusion <- as.data.frame(table(actual = test_true_class, predicted = test_pred_class)) plot <- ggplot(confusion) plot + geom_tile(aes...