AI/Codestates
[Day 30] Evaluation Metrics for Classification
JooJaeHwan
2022. 3. 4. 14:56
728x90
반응형
코딩부트캠프 | 코드스테이츠 - 비전공생도 개발자가 될 수 있습니다
코딩부트캠프를 찾는다면? 개발자로 커리어 전환을 위한 책임있는 코딩 교육 기관! 서비스 기획자, 그로스 마케터, 데이터 사이언티스트 등 다양한 전문 커리어에 도전하세요. 취업 성공의 후기
www.codestates.com
Warm-up
- Precision
- Recall
- Confusion Matrix
- Classification
Note
- Confusion Matrix
from sklearn.metrics import plot_confusion_matrix
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
pcm = plot_confusion_matrix(pipe, X_val, y_val,
cmap=plt.cm.Purples,
ax=ax);
plt.title(f'Confusion matrix, n = {len(y_val)}', fontsize=15)
plt.show()
- 정밀도 ( Precision ) : Positive로 예측한 경우 중 올바르게 Positive를 맞춘 비율
- 재현율 ( Recall ) : 실제 Positive인 것 중 올바르게 Positive를 맞춘 비율
- F1-Score : 정밀도와 재현율의 조화평균이다.
- 임계값
from ipywidgets import interact, fixed
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.metrics import classification_report
def explore_threshold(y_true, y_pred_proba, threshold=0.5):
y_pred = y_pred_proba >= threshold
vc = pd.Series(y_pred).value_counts()
ax = sns.histplot(y_pred_proba, kde=True)
ax.axvline(threshold, color='red')
ax.set_title(f'# of target, 1={vc[1]}, 0={vc[0]}')
plt.show()
print(classification_report(y_true, y_pred))
interact(explore_threshold,
y_true=fixed(y_val),
y_pred_proba=fixed(y_pred_proba),
threshold=(0, 1, 0.01));
- ROC ( Receiver Operating Characteristic ) : 머신러닝의 이진 분류 모델의 예측 성능을 판단하는 중요한 평가지표
fpr, tpr, thresholds = roc_curve(y_val, y_pred_proba)
roc = pd.DataFrame({
'FPR(Fall-out)': fpr,
'TPRate(Recall)': tpr,
'Threshold': thresholds
})
roc
plt.scatter(fpr, tpr)
plt.title('ROC curve')
plt.xlabel('FPR(Fall-out)')
plt.ylabel('TPR(Recall)');
- AUC ( Area Under Curve ) : ROC 곡선 밑의 면적을 구한 것
from sklearn.metrics import roc_auc_score
auc_score = roc_auc_score(y_val, y_pred_proba)
auc_score
Review
더보기
오늘은 분류모뎅의 평가지표에 대해 더 알아보았다. 점점 Interact의 사용법이 익숙해져 가고 있는거 같다
참고
728x90
반응형