Evaluation using test data

The code to obtain the loss and accuracy values from the test data is as follows:

model %>% evaluate(test_x, test_y)
$loss
[1] 0.4431483
$acc
[1] 0.79356

As we can see, in terms of the test data, the loss and accuracy are 0.443 and 0.794, respectively. These results are slightly inferior to the ones that were obtained for the training data. We can predict classes for the test data using the model and compare them with the actual classes of the movie reviews. This can be summarized in a confusion matrix, as follows:

pred1 <- model %>%   predict_classes(test_x)
table(Predicted=pred1, Actual=imdb$test$y)
Actual
Predicted 0 1
0 10586 3247
1 1914 9253

From the preceding confusion matrix, we can observe the following:

  • Overall, this model seems to be more accurate in correctly predicting negative movie reviews (10,586) compared to positive movie reviews (9,253).
  • This pattern is consistent with the results that were obtained with the training data.
  • In addition, although 79% accuracy for test data is decent, there is still scope for improving the model's sentiment classification performance.

In the next section, we will explore performance optimization tips and best practices.

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

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