-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermute_test.py
73 lines (57 loc) · 2.55 KB
/
permute_test.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
67
68
69
70
71
72
73
import argparse
import yaml
import numpy as np
from permute.core import one_sample
def permute(results):
baseline = np.array(results['baseline']['acc'])
logit = np.array(results['logit']['acc'])
rf = np.array(results['rf']['acc'])
baseline_f1 = np.array(results['baseline']['f1'])
logit_f1 = np.array(results['logit']['f1'])
rf_f1 = np.array(results['rf']['f1'])
baseline_roc = np.array(results['baseline']['roc_auc'])
logit_roc = np.array(results['logit']['roc_auc'])
rf_roc = np.array(results['rf']['roc_auc'])
logit_lift = logit - baseline
print('model\t\tAUC\t\tF1\t\tmean\t\tdiff\tp-value')
print('baseline\t{roc:.3f} ({roc_std:.3f})\t{f1:.3f} ({f1_std:.3f})\t{acc:.3f} ({acc_std:.3f})'.format(
roc=baseline_roc.mean(), roc_std=baseline_roc.std(),
f1=baseline_f1.mean(), f1_std=baseline_f1.std(),
acc=baseline.mean(), acc_std=baseline.std()))
(p, diff_means) = one_sample(logit_lift, stat='mean')
print('Logit\t\t{roc:.3f} ({roc_std:.3f})\t{f1:.3f} ({f1_std:.3f})\t{acc:.3f} ({acc_std:.3f})\t{diff:.3f}\t{p:.3f}'.format(
roc=logit_roc.mean(), roc_std=logit_roc.std(),
f1=logit_f1.mean(), f1_std=logit_f1.std(),
acc=logit.mean(), acc_std=logit.std(),
diff=diff_means, p=p))
rf_lift = rf - baseline
(p, diff_means) = one_sample(rf_lift, stat='mean')
print('RF\t\t{roc:.3f} ({roc_std:.3f})\t{f1:.3f} ({f1_std:.3f})\t{acc:.3f} ({acc_std:.3f})\t{diff:.3f}\t{p:.3f}'.format(
roc=rf_roc.mean(), roc_std=rf_roc.std(),
f1=rf_f1.mean(), f1_std=rf_f1.std(),
acc=rf.mean(), acc_std=rf.std(),
diff=diff_means, p=p))
def main():
np.random.seed(1)
parser = argparse.ArgumentParser()
parser.add_argument("-mo", type=str, help="movie yaml")
parser.add_argument("-mu", type=str, help="music yaml")
parser.add_argument("-mw", type=str, help="music+walk yaml")
args = parser.parse_args()
if args.mo:
movie_results = yaml.load(open(args.mo), Loader = yaml.UnsafeLoader)
print('^' * 20)
print('Movie')
permute(movie_results)
if args.mu:
music_results = yaml.load(open(args.mu), Loader = yaml.UnsafeLoader)
print('^' * 20)
print('Music')
permute(music_results)
if args.mw:
music_walk_results = yaml.load(open(args.mw), Loader = yaml.UnsafeLoader)
print('^' * 20)
print('Music + walking')
permute(music_walk_results)
if __name__ == "__main__":
main()