혼동 행렬(Confusion Marix)
실제 값(정답)과 예측 한 것을 표로 만든 평가표
함수: confusion_matrix(정답, 모델예측값)
결과의 0번축: 실제 class, 1번 축: 예측 class
TP(True Positive)
TN(True Negative)
FP(False Positive)
FN(False Negative)
이진 분류 평가지표
양성(Positive) 예측력 측정 평가지표
Recall/Sensitivity(재현율/민감도)
Precision(정밀도)
F1 점수
음성(Negative) 예측력 측정 평가지표
1 - 특이도
각 평가 지표 계산
from sklearn.metrics import (confusion_matrix, ConfusionMatrixDisplay, plot_confusion_matrix, accuracy_score,
recall_score, precision_score, f1_score)
# 혼동행렬
print(confusion_matrix(y_train, pred_train))
# 혼동행렬 시각화
plot_confusion_matrix(dummy_model,
x_test, y_test,
display_labels=["Neg", "Pos"],
cmap='Blues')
# 지표 계산
print('accuracy:', accuracy_score(y_train, pred_train))
print('recall:', recall_score(y_train, pred_train))
print('precision:', precision_score(y_train, pred_train))
print('f1 score:', f1_score(y_train, pred_train))
# recall, precision, f1-score를 한번에 보여주는 함수
from sklearn.metrics import classification_report
result = classification_report(y_train, pred_train_tree)
print(result)
PR Curve와 AP Score
from sklearn.metrics import precision_recall_curve
precision_list, recall_list, threshold_list = precision_recall_curve(y_test, pred_test_proba[:,1])
ROC curve(Receiver Operating Characteristic Curve)와 AUC(Area Under the Curve) score
ROC Curve
AUC Score