"test/srt/models/test_encoder_embedding_models.py" did not exist on "f6f713797bcbc63d225136d66deaa00495cdedfe"
utils.py 867 Bytes
Newer Older
KounianhuaDu's avatar
KounianhuaDu committed
1
2
import numpy as np
import torch
3
4
5
6
7
8
9
10
11
from sklearn.metrics import (
    accuracy_score,
    average_precision_score,
    f1_score,
    log_loss,
    ndcg_score,
    roc_auc_score,
)

KounianhuaDu's avatar
KounianhuaDu committed
12
13

def evaluate_auc(pred, label):
14
    res = roc_auc_score(y_score=pred, y_true=label)
KounianhuaDu's avatar
KounianhuaDu committed
15
16
    return res

17

KounianhuaDu's avatar
KounianhuaDu committed
18
19
20
21
22
23
24
25
26
def evaluate_acc(pred, label):
    res = []
    for _value in pred:
        if _value >= 0.5:
            res.append(1)
        else:
            res.append(0)
    return accuracy_score(y_pred=res, y_true=label)

27

KounianhuaDu's avatar
KounianhuaDu committed
28
29
30
31
32
33
34
35
36
def evaluate_f1_score(pred, label):
    res = []
    for _value in pred:
        if _value >= 0.5:
            res.append(1)
        else:
            res.append(0)
    return f1_score(y_pred=res, y_true=label)

37

KounianhuaDu's avatar
KounianhuaDu committed
38
def evaluate_logloss(pred, label):
39
    res = log_loss(y_true=label, y_pred=pred, eps=1e-7, normalize=True)
KounianhuaDu's avatar
KounianhuaDu committed
40
    return res