-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_metric.py
48 lines (45 loc) · 1.29 KB
/
task_metric.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# !/usr/bin/python3.7
# -*-coding:utf-8-*-
# Author: Hu Nan
# CreatDate: 2021/7/6 13:17
# Description:
from sklearn.metrics import (
precision_recall_fscore_support,
accuracy_score,
classification_report,
confusion_matrix,
)
import logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
datefmt="%m/%d/%Y %H:%M:%S",
level=logging.INFO,
)
logger = logging.getLogger(__name__)
log = logger
def compute_metrics(preds, labels):
log.info("compute_metrics is running ...")
precision, recall, f1, _ = precision_recall_fscore_support(
labels, preds, average="micro"
)
acc = accuracy_score(labels, preds)
class_rep = classification_report(
labels,
preds,
target_names=["SUPPORTS", "REFUTES", "NOT ENOUGH INFO"],
output_dict=False,
)
conf_matrix = confusion_matrix(labels, preds)
log.info(f"compute_metrics class_rep : {class_rep}")
log.info(
f"compute_metrics acc : {acc} recall : {recall} precision : {precision} f1 : {f1}"
)
log.info(f"compute_metrics conf_matrix : {conf_matrix}")
return {
"accuracy": acc,
"f1": f1,
"precision": precision,
"recall": recall,
"class_rep": class_rep,
"conf_matrix": conf_matrix,
}