-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSvmPipeline.java
75 lines (60 loc) · 2.33 KB
/
SvmPipeline.java
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
package org.dkpro.tc.ml.libsvm;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.dkpro.tc.ml.libsvm.api.LibsvmPredict;
import org.dkpro.tc.ml.libsvm.api.LibsvmTrainModel;
public class SvmPipeline {
public static void main(String[] args) throws IOException {
LibsvmTrainModel trainModel = new LibsvmTrainModel();
String[] argv = {"-s","0","-t","2","-d","3","-g","0","-r","0","-n","0.5","-m","100","-c","1","-e","1e-3","-p","0.1","-h","1","-b","0","src/main/resources/WingOfVictory"};
try {
trainModel.run(argv);
} catch (Exception e) {
e.printStackTrace();
}
LibsvmPredict predict = new LibsvmPredict();
String[] arg = {"-b","0","src/main/resources/WingOfVictoryTest","WingOfVictory.model","src/main/resources/WingOfVictoryOutput"};
try {
predict.main(arg);
} catch (IOException e) {
e.printStackTrace();
}
try {
// File createTempFile = FileUtil.createTempFile("labelModified", ".tmp");
BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream("src/main/resources/OutputCompare.dat")));
File output = new File("src/main/resources/WingOfVictoryOutput");
File test = new File("src/main/resources/WingOfVictoryTest");
List<Double> outputs = new ArrayList<>();
for (String s : FileUtils.readLines(output)) {
if (s.isEmpty()) {
continue;
}
outputs.add(Double.parseDouble(s));
}
List<Double> tests = new ArrayList<>();
for (String s : FileUtils.readLines(test)) {
if (s.isEmpty()) {
continue;
}
tests.add(Double.parseDouble(s.split("\t")[0]));
}
for (int i=0;i<outputs.size();i++) {
bw.write(String.valueOf(outputs.get(i)));
bw.write("("+String.valueOf(tests.get(i))+")");
bw.write("\n");
}
bw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}