교 향
Maximalism
교 향
전체 방문자
오늘
어제
  • 전체글
    • Coding
    • Linux
    • Docker
    • Python
    • AI
      • GPT
      • Pandas
      • Numpy
      • tensorflow
      • pytorch
      • openCV
      • Study
      • AIconnect - [GPT]한국어..
    • Data structure, OS
    • Competitions
    • Investment
    • Book
    • Health
    • Trip
    • Memo
    • 대학원

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • AI면접 #딥러닝면접 #인공지능면접 #기울기소실 #GradientVanishing
  • ActivationFunction #활성화함수 #인공지능면접

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
교 향

Maximalism

[accuracy_score] 사이킷런과 케라스의 차이
AI

[accuracy_score] 사이킷런과 케라스의 차이

2022. 10. 31. 16:05

[원인 : model.evaluate의 accuracy 결과가 confusion matrix를 계산한 accuracy 결과와 달랐음]

 

 

confusion matrix

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
    'AI' 카테고리의 다른 글
    • CNN Channel에서 grayscale혹은 rgb scale을 적용해야 할까?
    • 표준화, 정규화 딱 이해
    • [keras_IDG]flow_from_dataframe
    • Early stopping 에서 epoch를 인자값으로 받아올 때
    교 향
    교 향
    AI/ML/DL

    티스토리툴바