Support Vector Machine / サポートベクターマシン / 支持向量机

Source code on Github: here Java OOP Port from C LibSVM library

Linear Kernel Gaussian Kernel
Polynomial Kernel Polynomial Kernel

Problem Loaders

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
IProblemLoader loader = new LibSVMProblemLoader();

Problem train = loader.load("svm/data/libsvm/linear_train.libsvm");
Problem test = loader.load("svm/data/libsvm/linear_test.libsvm");
/*
The typical LibSVM format, the first item represents the Class, the remaining
elements are prefixed by the index in the vector input that they represent

-1 1:1 2:1
-1 1:1 2:-1
-1 1:-1 2:1
-1 1:-1 2:-1
+1 1:5 2:5
+1 1:10 2:10
+1 2:10
*/

IProblemLoader loader = new SimpleProblemLoader();
Problem train = loader.load("svm/data/linear_train.svm");
Problem test = loader.load("svm/data/linear_test.svm");
/*
In this simple format, the first item represents the Class, the remaining
elements represent features of the class
i.e. -1 1 1 means Class = -1, input vector <1, 1>.
this simple format does not allow for sparse vectors

-1 1 1
-1 1 -1
-1 -1 1
-1 -1 -1
1 5 5
1 10 10
1 0 10
*/

Sample Outputs

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
Loading problem: svm/data/linear_train.svm
-1: 1 1
-1: 1 -1
-1: -1 1
-1: -1 -1
1: 5 5
1: 10 10
1: 0 10
Loading problem: svm/data/linear_test.svm
-1: 1 1
-1: 1 -1
-1: -1 1
-1: -1 -1
1: 5 5
1: 10 10
1: 0 10
Loaded.
Training...
Testing...
-1: 1.0 1.0
-1: 1.0 -1.0
-1: -1.0 1.0
-1: -1.0 -1.0
1: 5.0 5.0
1: 10.0 10.0
1: 0.0 10.0
7/7 correct
Accuracy=1.0
Done.
comments powered by Disqus