티스토리 뷰

ML

ROC Curve & AUC Curve

마로그래머 2023. 7. 27. 00:01
반응형

ROC Curve (Receiver Operating Characteristic) & AUC Curve (Area Under the Curve)

ROC Curve 는 이진분류에서 클래스별 분포가 다를 때, Accuracy의 단점을 보완하기 위해 사용된다.

다양한 임계값에서 FPR(1-Specificity) 에 대한 TPR(Recall) 값 을 플롯하고 noise를 제거하여 signal을 얻는 커브이다.

AUC CurveROC Curve의 밑부분을 뜻하며 이 AUC 커브를 이용하여 퍼포먼스를 확인한다.

결과만 말하자면, AUC Curve가 높이 향할 수록 PositiveNegative 를 잘 구분할 수 있는 모델인 것이다.



구현

  • sklearn 으로 간단하게 구현 가능하다.
from sklearn.metrics import roc_curve

# roc curve for models
fpr1, tpr1, thresh1 = roc_curve(y_test, pred_prob1[:,1], pos_label=1)
fpr2, tpr2, thresh2 = roc_curve(y_test, pred_prob2[:,1], pos_label=1)

# roc curve for tpr = fpr 
random_probs = [0 for i in range(len(y_test))]
p_fpr, p_tpr, _ = roc_curve(y_test, random_probs, pos_label=1)



AUC score도 확인할 수 있다.

from sklearn.metrics import roc_auc_score

# auc scores
auc_score1 = roc_auc_score(y_test, pred_prob1[:,1])
auc_score2 = roc_auc_score(y_test, pred_prob2[:,1])

print(auc_score1, auc_score2)

  • matplotilb 로 나타낼 수 있다.
import matplotlib.pyplot as plt
plt.style.use('seaborn')

# plot roc curves
plt.plot(fpr1, tpr1, linestyle='--',color='orange', label='Logistic Regression')
plt.plot(fpr2, tpr2, linestyle='--',color='green', label='KNN')
plt.plot(p_fpr, p_tpr, linestyle='--', color='blue')
# title
plt.title('ROC curve')
# x label
plt.xlabel('False Positive Rate')
# y label
plt.ylabel('True Positive rate')

plt.legend(loc='best')
plt.savefig('ROC',dpi=300)
plt.show();




Multi-Class Classification에서의 AUC-ROC

One vs All 방법을 써서 이진분류에 사용되는 AUC-ROC를 다중분류에 사용할 수 있다.

근데 이건 내가 아직 멀티클래스분류를 안 배워서 봐도 이해가 안가서 여기선 정리안하겠다.

대신 여기를 참조하자.

반응형

'ML' 카테고리의 다른 글

오차행렬 (Confusion Matrix)  (0) 2023.07.27
9. 배치 정규화 (Batch Normalization)  (0) 2023.07.26
8. 하이퍼파라미터 튜닝 (Hyperparameter Tuning)  (0) 2023.07.26
7. 학습률 감쇠 (Learning Decay), Local Optima  (0) 2023.07.24
6. Adam  (0) 2023.07.24
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함