forked from stephenliu0423/PyDTI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_eval.py
132 lines (119 loc) · 6.61 KB
/
cv_eval.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import time
from functions import *
from nrlmf import NRLMF
from netlaprls import NetLapRLS
from blm import BLMNII
from wnngip import WNNGIP
from kbmf import KBMF
from cmf import CMF
def nrlmf_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_auc, auc_opt = 0, []
for r in [50, 100]:
for x in np.arange(-5, 2):
for y in np.arange(-5, 3):
for z in np.arange(-5, 1):
for t in np.arange(-3, 1):
tic = time.clock()
model = NRLMF(cfix=para['c'], K1=para['K1'], K2=para['K2'], num_factors=r, lambda_d=2**(x), lambda_t=2**(x), alpha=2**(y), beta=2**(z), theta=2**(t), max_iter=100)
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if auc_avg > max_auc:
max_auc = auc_avg
auc_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % auc_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (auc_opt[1], auc_opt[2], auc_opt[3], auc_opt[4])
print cmd
def netlaprls_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_auc, auc_opt = 0, []
for x in np.arange(-6, 3): # [-6, 2]
for y in np.arange(-6, 3): # [-6, 2]
tic = time.clock()
model = NetLapRLS(gamma_d=10**(x), gamma_t=10**(x), beta_d=10**(y), beta_t=10**(y))
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if auc_avg > max_auc:
max_auc = auc_avg
auc_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % auc_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (auc_opt[1], auc_opt[2], auc_opt[3], auc_opt[4])
print cmd
def blmnii_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_auc, auc_opt = 0, []
for x in np.arange(0, 1.1, 0.1):
tic = time.clock()
model = BLMNII(alpha=x, avg=False)
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if auc_avg > max_auc:
max_auc = auc_avg
auc_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % auc_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (auc_opt[1], auc_opt[2], auc_opt[3], auc_opt[4])
print cmd
def wnngip_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_auc, auc_opt = 0, []
for x in np.arange(0.1, 1.1, 0.1):
for y in np.arange(0.0, 1.1, 0.1):
tic = time.clock()
model = WNNGIP(T=x, sigma=1, alpha=y)
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if auc_avg > max_auc:
max_auc = auc_avg
auc_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % auc_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (auc_opt[1], auc_opt[2], auc_opt[3], auc_opt[4])
print cmd
def kbmf_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_auc, auc_opt = 0, []
for d in [50, 100]:
tic = time.clock()
model = KBMF(num_factors=d)
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if auc_avg > max_auc:
max_auc = auc_avg
auc_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % auc_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (auc_opt[1], auc_opt[2], auc_opt[3], auc_opt[4])
print cmd
def cmf_cv_eval(method, dataset, cv_data, X, D, T, cvs, para):
max_aupr, aupr_opt = 0, []
for d in [50, 100]:
for x in np.arange(-2, -1):
for y in np.arange(-3, -2):
for z in np.arange(-3, -2):
tic = time.clock()
model = CMF(K=d, lambda_l=2**(x), lambda_d=2**(y), lambda_t=2**(z), max_iter=30)
cmd = "Dataset:"+dataset+" CVS: "+str(cvs)+"\n"+str(model)
print cmd
aupr_vec, auc_vec = train(model, cv_data, X, D, T)
aupr_avg, aupr_conf = mean_confidence_interval(aupr_vec)
auc_avg, auc_conf = mean_confidence_interval(auc_vec)
print "auc:%.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f, Time:%.6f\n" % (auc_avg, aupr_avg, auc_conf, aupr_conf, time.clock()-tic)
if aupr_avg > max_aupr:
max_aupr = aupr_avg
aupr_opt = [cmd, auc_avg, aupr_avg, auc_conf, aupr_conf]
cmd = "Optimal parameter setting:\n%s\n" % aupr_opt[0]
cmd += "auc: %.6f, aupr: %.6f, auc_conf:%.6f, aupr_conf:%.6f\n" % (aupr_opt[1], aupr_opt[2], aupr_opt[3], aupr_opt[4])
print cmd