-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheval.py
More file actions
32 lines (26 loc) · 939 Bytes
/
Copy patheval.py
File metadata and controls
32 lines (26 loc) · 939 Bytes
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
import string
from sklearn.metrics import f1_score
from sklearn.metrics import confusion_matrix
import argparse
parser = argparse.ArgumentParser(description='main', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--dataset', default='bio', choices=['bio', 'ai', 'cyber', 'amazon', 'twitter'])
args = parser.parse_args()
dataset = args.dataset
train = []
with open(f'{dataset}/doc_id.txt') as fin:
for line in fin:
idx = line.strip().split(':')[1].split(',')
train += [int(x) for x in idx]
y = []
with open(f'{dataset}/dataset.csv') as fin:
for idx, line in enumerate(fin):
if idx not in train:
y.append(line.strip().split(',')[0])
y_pred = []
with open(f'{dataset}/out.txt') as fin:
for idx, line in enumerate(fin):
if idx not in train:
y_pred.append(line.strip())
print(f1_score(y, y_pred, average='micro'))
print(f1_score(y, y_pred, average='macro'))
print(confusion_matrix(y, y_pred))