<目次>
(1) Kerasで「AttributeError: ‘Sequential’ object has no attribute ‘XXX’」エラー原因・対処(+predict_classes関数やpredict_proba関数の解説)
(1-1) 事象
(1-2) 原因
(1-3) 対策
(1-4) 参考①:predict_classes()関数について
(1-5) 参考②:predict_proba()関数について
(1-6) 参考③:対処の背景
(1) Kerasで「AttributeError: ‘Sequential’ object has no attribute ‘XXX’」エラー原因・対処(+predict_classes関数やpredict_proba関数の解説)
(1-1) 事象
Traceback (most recent call last): File "c:\\ xxxxxx\\xxxxx.py", line NN, in XXXXX classes = model.predict_classes(X,batch_size=1) AttributeError: 'Sequential' object has no attribute 'predict_classes'
Traceback (most recent call last): File "c:\\ xxxxxx\\xxxxx.py", line NN, in XXXXX prob = model.predict_proba(X,batch_size=1) AttributeError: 'Sequential' object has no attribute 'predict_proba'


(1-2) 原因
(1-3) 対策
●「predict_classes」の対策
classes = model.predict_classes(X,batch_size=1)
classes = np.argmax(model.predict(X),axis=1)
classes = (model.predict(X) > 0.5).astype("int32")
●「predict_proba」の対策
prob = model.predict_proba(X,batch_size=1)
prob = model.predict(X,batch_size=1)

(1-4) 参考①:predict_classes()関数について
t = np.array([[0],[1],[1],[1]])
classified: [[False] [ True] [ True] [ True]] probability: [[0.5082121] [0.7830747] [0.8921545] [0.9665527]]

classified: [[True] [ True] [ True] [ True]] probability: [[0. 45884573] [0.7830747] [0.8921545] [0.9665527]]

(1-5) 参考②:predict_proba()関数について
t = np.array([[0],[1],[1],[1]])
(1-6) 参考③:対処の背景
C:\\XXXXXXX\\lib\\site-packages\\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). warnings.warn('model.predict_classes() is deprecated and '