[원인 : model.evaluate의 accuracy 결과가 confusion matrix를 계산한 accuracy 결과와 달랐음]
tensorflow로 다중분류 모델을 돌려서 얻은 결과가 위와 같았는데
loss, acc = model.evaluate(test_data)
print(f'Accuracy : {str(np.round(acc, 2)*100)+"%"}, Loss : {np.round(loss, 2)}')
# 결과
1/1 [==============================] - 1s 512ms/step - loss: 3.6820 - accuracy: 0.5238
Accuracy : 52.0%, Loss : 3.68
결과가 아래와 같았다. accuracy가 0.52라고 하였으나,
단순히 계산해도 accuracy는 (7+3+1+11) / 78 = 0.28 의 엄청난 저성능이어야 했다.
(confusion matrix 개념은 다른분 참고 :
https://growing-tr2.tistory.com/40,
https://data-newbie.tistory.com/155,
https://moons08.github.io/datascience/classification_score_basic/ )
"사이킷런과 케라스의 accuracy_score가 서로 다르기 때문" 이었다.
( accuracy가 다른 이유 검색 결과 : https://github.com/keras-team/keras/issues/9672 )
하여, 아래와 같이 사용하니 결과가 옳게 나왔다.
from sklearn.metrics import accuracy_score
accuracy_score = accuracy_score(y_true,y_predict)
print(f'Accuracy : {str(np.round(accuracy_score, 2)*100)+"%"}')
##result
0.28
Different accuracy score between keras.model.evaluate and sklearn.accuracy_score · Issue #9672 · keras-team/keras
I have a similar problem with this Kaggle tutorial: https://www.kaggle.com/eliotbarr/text-mining-with-sklearn-keras-mlp-lstm-cnn, so I will refer to it. If you look to the code block number 30 and ...
github.com
https://github.com/keras-team/keras/issues/9672
'AI' 카테고리의 다른 글
CNN Channel에서 grayscale혹은 rgb scale을 적용해야 할까? (0) | 2022.11.23 |
---|---|
표준화, 정규화 딱 이해 (0) | 2022.11.18 |
[keras_IDG]flow_from_dataframe (0) | 2022.10.27 |
Early stopping 에서 epoch를 인자값으로 받아올 때 (0) | 2022.10.24 |
미드저니 (0) | 2022.09.16 |