forked from XunGuangxu/CorNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation.py
34 lines (28 loc) · 1.79 KB
/
evaluation.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
import warnings
warnings.filterwarnings('ignore')
import click
import numpy as np
from sklearn.preprocessing import MultiLabelBinarizer
from deepxml.evaluation import get_p_1, get_p_3, get_p_5, get_n_1, get_n_3, get_n_5, get_inv_propensity
from deepxml.evaluation import get_psp_1, get_psp_3, get_psp_5, get_psndcg_1, get_psndcg_3, get_psndcg_5
@click.command()
@click.option('-r', '--results', type=click.Path(exists=True), help='Path of results.')
@click.option('-t', '--targets', type=click.Path(exists=True), help='Path of targets.')
@click.option('--train-labels', type=click.Path(exists=True), default=None, help='Path of labels for training set.')
@click.option('-a', type=click.FLOAT, default=0.55, help='Parameter A for propensity score.')
@click.option('-b', type=click.FLOAT, default=1.5, help='Parameter B for propensity score.')
def main(results, targets, train_labels, a, b):
res, targets = np.load(results, allow_pickle=True), np.load(targets, allow_pickle=True)
mlb = MultiLabelBinarizer(sparse_output=True)
targets = mlb.fit_transform(targets)
print('Precision@1,3,5:', get_p_1(res, targets, mlb), get_p_3(res, targets, mlb), get_p_5(res, targets, mlb))
print('nDCG@1,3,5:', get_n_1(res, targets, mlb), get_n_3(res, targets, mlb), get_n_5(res, targets, mlb))
if train_labels is not None:
train_labels = np.load(train_labels, allow_pickle=True)
inv_w = get_inv_propensity(mlb.transform(train_labels), a, b)
print('PSPrecision@1,3,5:', get_psp_1(res, targets, inv_w, mlb), get_psp_3(res, targets, inv_w, mlb),
get_psp_5(res, targets, inv_w, mlb))
print('PSnDCG@1,3,5:', get_psndcg_1(res, targets, inv_w, mlb), get_psndcg_3(res, targets, inv_w, mlb),
get_psndcg_5(res, targets, inv_w, mlb))
if __name__ == '__main__':
main()