'How to replace predict_classes() in R?

I would like to post a confusion matrix from this binary classification

classes <- model %>% predict_classes(X_test, batch_size = batch_size)

With

table(y_test, classes)

Since the predict_classes method is deprecated and was removed from tensorflow in version 2.6., I wonder what the solution must look like.

Or do I just not understand the fix below?

The error code tells me:

  • if your model does binary classification (e.g. if it uses a sigmoid last-layer activation).

    model %>% predict(x) %>% `>`(0.5) %>% k_cast("int32")
    

Does someone encounter the same issue? For multi-class classification, it seems to work.

It is an example from kaggle



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source