dipanjanS / practical-machine-learning-with-python

Master the essential skills needed to recognize and solve complex real-world problems with Machine Learning and Deep Learning by leveraging the highly popular Python Machine Learning Eco-system.
Apache License 2.0
2.27k stars 1.65k forks source link

Chapter 9 error Tensorflow AttributeError: 'Sequential' object has no attribute 'predict_class' because predict_class() changed to predict() #32

Open richlysakowski opened 2 years ago

richlysakowski commented 2 years ago

AttributeError Traceback (most recent call last) Input In [41], in <cell line: 3>() 1 # AFTER changing the code, the line runs without error: ----> 3 wtp_dnn_ypred = wtp_dnn_model.predict_class(wtp_test_SX) 4 wtp_dnn_ypred

AttributeError: 'Sequential' object has no attribute 'predict_class'

######################

I found a solution to this...

Original CODE FAILED due to a change in Tensorflow 2.6 in May-June 2022

Problem described here:

https://stackoverflow.com/questions/68836551/keras-attributeerror-sequential-object-has-no-attribute-predict-classes

wtp_dnn_ypred` = wtp_dnn_model.predict_classes(wtp_test_SX)

This was changed to:

wtp_dnn_ypred = wtp_dnn_model.predict(wtp_test_SX)

dipanjanS commented 2 years ago

Yes unfortunately TensorFlow has removed that function.

You can use the Model Evaluation code here and reuse the same in the other model https://github.com/dipanjanS/adv_nlp_workshop_odsc_europe22/blob/main/02_NLP_Applications_Text_Classification_Deep_Learning_CNN_Models.ipynb

Hope this helps.

On Wed, Jul 6, 2022 at 4:01 AM Rich Lysakowski @.***> wrote:


AttributeError Traceback (most recent call last) Input In [41], in <cell line: 3>() 1 # AFTER changing the code, the line runs without error: ----> 3 wtp_dnn_ypred = wtp_dnn_model.predict_class(wtp_test_SX) 4 wtp_dnn_ypred

AttributeError: 'Sequential' object has no attribute 'predict_class'

######################

I found a solution to this...

Original CODE FAILED due to a change in Tensorflow 2.6 in May-June 2022

Problem described here:

https://stackoverflow.com/questions/68836551/keras-attributeerror-sequential-object-has-no-attribute-predict-classes

wtp_dnn_ypred` = wtp_dnn_model.predict_classes(wtp_test_SX)

This was changed to:

wtp_dnn_ypred = wtp_dnn_model.predict(wtp_test_SX)

— Reply to this email directly, view it on GitHub https://github.com/dipanjanS/practical-machine-learning-with-python/issues/32, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2J3R46YRODO2STK234XN3VSSZVXANCNFSM52XVOIWA . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>