Recent Posts
Recent Comments
Archives
Today
Total
05-21 04:42
관리 메뉴

이것저것 잡동사니

[예제 코드] 분류 모델에 사용되는 성능 평가 지표 (sklearn 사용) 본문

컴퓨터공학/예제 코드

[예제 코드] 분류 모델에 사용되는 성능 평가 지표 (sklearn 사용)

Park Siyoung 2022. 7. 21. 04:34
반응형

    아래의 모든 코드에는 예측 클래스와 실제 클래스를 랜덤으로 각각 100개씩 생성하는 다음 코드를 생략하고 작성했다.

import numpy as np

y_pred = np.random.randint(2, size=100)  # 100 Predictions (0 or 1)
y_true = np.random.randint(2, size=100)  # 100 True Classes (0 or 1)

 

1. 정확도(Accuracy)

from sklearn.metrics import accuracy_score

print(accuracy_score(y_true, y_pred))

 

2. 오차 행렬(Confusion Matrix)

from sklearn.metrics import confusion_matrix

print(confusion_matrix(y_true, y_pred))
'''
Output : [[TN FP]
          [FN TP]]
'''

 

3. 정밀도(Precision)

from sklearn.metrics import precision_score

print(precision_score(y_true, y_pred))

 

4. 재현율(Recall)

from sklearn.metrics import recall_score

print(recall_score(y_true, y_pred))

 

5. F1 스코어(F1 Score)

from sklearn.metrics import f1_score

print(f1_score(y_true, y_pred))

 

ROC-AUC, Precision-Recall Curve 등 추가 예정...

 

반응형
Comments