-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
77 lines (46 loc) · 1.29 KB
/
example.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from Ordinalkdl import Ordinalkdl
import pickle
import scipy.io
import time
def main():
# load dataset
# BE SURE THAT DATA FIT INTO THE MEMORY OF YOUR MACHINE
x = np.loadtxt('test/train_toy.0')
y = np.loadtxt('test/test_toy.0')
train_feat = x[:, 0:2]
train_labels = x[:,2]
test_feat = y[:, 0:2]
test_labels = y[:,2]
param =np.zeros((2, 1))
kernel = "gaussian"
optmethod = "cvx"
gamma = 0.1
C = 10.
u = 0.001
param[0] = gamma
param[1] = u
#
kdlor = Ordinalkdl( kernel, param, optmethod, C )
# print x.shape, y.shape
## For training ##
# Training the model
tic = time.time()
kdlormodel = kdlor.Learn( train_feat, train_labels )
toc =time.time()
t_train = (toc - tic)/60.
print 'trainning time', t_train
# save the kdlor model
#modelfile = open( 'data/kdlor_aging_model.pkl', 'wb' )
#pickle.dump( kdlormodel, modelfile )
#modelfile.close()
#print "training time (mn) = ", t_train
tic = time.time()
_, predicted = kdlor.Test( train_feat, test_feat, kdlormodel )
toc =time.time()
t_test = (toc - tic)/60.
print 'testing time', t_test
if __name__ == "__main__":
main()