Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

This function were removed in TensorFlow version 2.6. According to the keras in rstudio reference

update to

predict_x=model.predict(X_test) 
classes_x=np.argmax(predict_x,axis=1)

Or use TensorFlow 2.5 or later.

If you are using TensorFlow version 2.5, you will receive the following warning:

tensorflow\python\keras\engine\sequential.py:455: UserWarning: model.predict_classes() is deprecated and will be removed after 2021-01-01. Please use instead:* np.argmax(model.predict(x), axis=-1), if your model does multi-class classification (e.g. if it uses a softmax last-layer activation).* (model.predict(x) > 0.5).astype("int32"), if your model does binary classification (e.g. if it uses a sigmoid last-layer activation).


I experienced the same error, I use this following code, and succeed

Replaced:

predictions = model.predict_classess(x_test)

With this one:

predictions = (model.predict(x_test) > 0.5).astype("int32")

Type of python packages : Tensorflow 2.6.0

This works well


I used following code for predictions

y_pred = model.predict(X_test)
y_pred = np.round(y_pred).astype(int)