AI 이론/Classification (supervised)
[분류 러닝] 성능 측정 => Confusion Matrix
jasonshin
2021. 11. 24. 17:56
두 개의 클래스로 분류하는 경우는 아래와 같다.
# Negative = 0, Positive = 1
미탐지가 0에 가까울수록 적중율 상승,
미탐지가 적은것이 중요!
오탐지가 0에 가까울수록 정밀도 상승.
코딩
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cm
array([[51, 4],
[ 8, 17]], dtype=int64)
정확도 accuracy 계산식
맞춘것의 개수/ 전체 개수
(51+17) / cm.sum()
0.85
정확도 라이브러리 함수
from sklearn.metrics import accuracy_score
accuracy_score(y_test, y_pred)
0.85
from sklearn.metrics import classification_report
print(classification_report(y_test, y_pred))
precision recall f1-score support
0 0.86 0.93 0.89 55
1 0.81 0.68 0.74 25
accuracy 0.85 80
macro avg 0.84 0.80 0.82 80
weighted avg 0.85 0.85 0.85 80
반응형