-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
78 lines (62 loc) · 1.98 KB
/
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
74
75
76
77
78
from SHModel import CS, LN
from preprocess import PSH, ProData
import cPickle as pickle
import numpy as np
def CreatData(filename, savename, threshold):
psh=PSH(filename)
psh.process(threshold,savename)
def CreatSequence():
pd = ProData()
pd.ProAcFile()
def testSHM():
threshold = 150
#Load data
pkl_file = open('data.plk', 'rb')
pos, neg, Ni, Nr = pickle.load(pkl_file)
idx = np.random.permutation(len(Ni))
train_len = round(len(Ni) * 0.8)
train_idx = idx[:train_len]
test_idx = idx[train_len:]
x_train = [Ni[i] for i in train_idx]
y_train = [Nr[i] for i in train_idx]
x_test = [Ni[i] for i in test_idx]
y_test = [Nr[i] for i in test_idx]
#CS model test
cs = CS()
cs.train(x_train, y_train)
cs.predict(x_test)
print "RSE: %f" % cs.RSE(y_test)
print "precision: %f, recall: %f" % cs.PR(y_test,threshold)
#LN model test
ln = LN()
ln.train(x_train, y_train)
ln.predict(x_test)
print "RSE: %f" % ln.RSE(y_test)
print "precision: %f, recall: %f" % ln.PR(y_test,threshold)
if __name__ == "__main__":
threshold = 150
#CreatData('../../corpus_g2','data.plk',threshold) #just run once the pos: 425, the neg: 682
#Load data
pkl_file = open('sequence.plk', 'rb')
_ ,time = pickle.load(pkl_file)
idx = np.random.permutation(len(Ni))
train_len = round(len(Ni) * 0.8)
train_idx = idx[:train_len]
test_idx = idx[train_len:]
x_train = [Ni[i] for i in train_idx]
y_train = [Nr[i] for i in train_idx]
x_test = [Ni[i] for i in test_idx]
y_test = [Nr[i] for i in test_idx]
#CS model test
cs = CS()
cs.train(x_train, y_train)
cs.predict(x_test)
print "RSE: %f" % cs.RSE(y_test)
print "precision: %f, recall: %f" % cs.PR(y_test,threshold)
#LN model test
ln = LN()
ln.train(x_train, y_train)
ln.predict(x_test)
print "RSE: %f" % ln.RSE(y_test)
print "precision: %f, recall: %f" % ln.PR(y_test,threshold)
print 'exit'