본문 바로가기

Data Science/Machine Learning

[sklearn] multi-classification 문제에서 f1 score 사용하기

728x90
sklearn 패키지의 metrics.classficiation_report를 통해 multi-class 각각에 대한 f1 score를 편하게 구할 수 있다

 

F1 score (출처: https://abeyon.com/wp-content/uploads/2019/11/Prediction-measurements.png)

 

사용법

from sklearn import metrics

print(metrics.classification_report(y_true, y_pred, digits=3))

 

출력 예시

  • 아래와 같이 각 클래스별 f1-score가 표로 깔끔히 출력되는 것을 확인할 수 있다
              precision    recall  f1-score   support

     class 0       0.50      1.00      0.67         1
     class 1       0.00      0.00      0.00         1
     class 2       1.00      0.67      0.80         3

    accuracy                           0.60         5
   macro avg       0.50      0.56      0.49         5
weighted avg       0.70      0.60      0.61         5
반응형