-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.py
70 lines (41 loc) · 1.33 KB
/
merge.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#combines and evaluates all ensemble submodels into one auc score
import os
import numpy as np
import sys
from simplestat import statinf
import json
pwr=0
quiet=False
if len(sys.argv)>1:
try:
pwr=float(sys.argv[1])
except:
quiet=sys.argv[1]=="quiet"
cmax=100000
if len(sys.argv)>2:
cmax=int(sys.argv[2])
if not os.path.isdir("results"):exit()
fns=["results/"+zw+"/result.npz" for zw in os.listdir("results")][:cmax+10]
fns=[zw for zw in fns if os.path.isfile(zw)]
from sklearn.metrics import roc_auc_score as auc
y_scores=[]
y_true=None
for fn in fns:
f=np.load(fn,allow_pickle=True)
if y_true is None:
y_true=f["y_true"]
y_scores.append(f["y_score"])
#fs=[np.load(fn,allow_pickle=True) for fn in fns]
#screw double evaluation
#y_true=fs[0]["y_true"]
#le=int(2*(len(y_true)-sum(y_true)))
#y_true=y_true[:le]
#y_scores=[f["y_score"][:le] for f in fs]
y_scores=y_scores[:cmax]
aucs=[auc(y_true,y_score) for y_score in y_scores]
if not quiet:print(json.dumps([[statinf(aucs)]],indent=2))
wids=[np.std(y_score[np.where(y_true==0)]) for y_score in y_scores]
y_score=np.sqrt(np.mean([(y_score/wid**pwr)**2 for y_score,wid in zip(y_scores,wids)],axis=0))
auc_score=auc(y_true,y_score)
if not quiet:print("----------",auc_score)
np.savez_compressed("auc.npz",auc=auc_score,aucs=aucs,wids=wids)