-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSSVM_test.py
70 lines (37 loc) · 1.33 KB
/
LSSVM_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
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 25 20:39:12 2018
@author: Dynasting
"""
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 22 10:23:45 2017
@author: Dyt
"""
import LSSVM
import numpy
import Dataset
Train = numpy.loadtxt('dataset///monks_2_train.txt')
X = Train[:,1:-1]
Y = Train[:,0]
NorX = Dataset.Normalization()
NorX.fit(X)
NorY = Dataset.Normalization()
NorY.fit(Y)
X_N = NorX.fT(X)
Y_N = NorY.fT(Y)
Y_N = Y_N * 2 -1
Test = numpy.loadtxt('dataset///monks_2_test.txt')
X_t = Test[:,1:-1]
Y_t = Test[:,0]
X_N_t = NorX.fT(X_t)
Y_N_t = NorY.fT(Y_t)
Y_N_t = Y_N_t * 2 -1
(alpha,b,K) = LSSVM.LSSVM_CV(X_N,Y_N,'RBF',[0.01,0.1,0.5,1,2,10,25,50,100],[0.001,0.01,0.1,0.2,0.5,1,5,10,40,100],arg2 = None)
#(alpha,b,K) = LSSVM.LSSVM_CV(X_N,Y_N,'LINEAR',[0.001,0.005,0.01,0.05,0.1,0.5,1,4,10,25,100])
#(alpha,b,K) = LSSVM.LSSVM_CV(X_N,Y_N,'POLY',[0.01,0.1,0.5,1,2,10,25,50,100],[0.001,0.01,0.1,0.2,0.5,1,5,10,40,100],[1,2,3,4,5])
#(alpha,b,K) = LSSVM.LSSVM_CV(X_N,Y_N,'TANH',[0.01,0.1,0.5,1,2,10,25,50,100],[-10,-5,-3,-2,-1,-0.5,-0.1,-0.05,-0.01,0.01,0.05,0.1,0.5,1,3,5,10],[0.1,1,2,3,10])
#(alpha,b,K) = LSSVM.LSSVM_CV(X_N,Y_N,'TL1',[0.001,0.005,0.01,0.03,0.1,0.5,1,2,10,25,50,100],[0.001,0.005,0.01,0.05,0.1,0.2,0.5,1,2,5,10,20])
Y_predict = LSSVM._LSSVMpredict(X_N_t,K,alpha,b,Y_N)
acc = LSSVM._compare(Y_N_t,Y_predict)
print(acc)