[Error] 'Sequential' object has no attribute 'predict_classes'

Hyuntae Jung·2022년 3월 28일
0

https://dacon.io/competitions/open/235594/codeshare/899?page=1&dtype=recent

② 데이터 분석하기

설치 할 것들

To install this package with conda run one of the following:

conda install -c conda-forge keras
conda install -c conda-forge/label/broken keras
conda install -c conda-forge/label/cf201901 keras
conda install -c conda-forge/label/cf202003 keras

Error

##6. 학습한 모델로 test 데이터의 범주(클래스)를 예측합니다.
y_pred = cnn_model.predict_classes(x_test)

y_pred = cnn_model.predict_classes(x_test)
y_pred = cnn_model.predict_classes(x_test)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Users\Public\Documents\ESTsoft\CreatorTemp/ipykernel_20820/2762103647.py in <module>
----> 1 y_pred = cnn_model.predict_classes(x_test)

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

tensorflow 버전 2.6이후로 predict_classes가 없기 때문에 발생하는 오류

해결

before)

y_pred = cnn_model.predict_classes(x_test)

after)

y_pred0 = cnn_model.predict(x_test)
y_pred = y_pred0.argmax(axis=-1)

으로 수정

https://stackoverflow.com/questions/68776790/model-predict-classes-is-deprecated-what-to-use-instead

0개의 댓글