先挖个坑,有空重写svm_scale, svm_train, svm_predict几个代码,给的实在写的不敢恭维
package org.ml.svm; import java.io.File; import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; public class SVMTest { public static void main(String[] args) throws IOException { // BufferedReader bf = new BufferedReader(new FileReader("data\train.1")); // String line; // while((line = bf.readLine()) != null) System.out.println(line); //设置scale的参数,把输出重定向到文件中 String[] scale_train_ops = {"-l", "-1", "-u", "1", "-s", "data\range1", "data\train.1"}; String[] scale_test_ops = {"-r", "data\range1", "data\test.1"}; svm_scale s = new svm_scale(); System.setOut(new PrintStream(new File("data\train.1.scale"))); s.main(scale_train_ops); System.setOut(new PrintStream(new File("data\test.1.scale"))); s.main(scale_test_ops); //把输出重定向会console上 System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); //设置训练和测试的参数 String[] train_ops = {"data\train.1.scale", "data\train.1.model"}; String[] test_ops = {"data\test.1.scale", "data\train.1.model", "data\out.1"}; System.out.println("SVM start:"); svm_train t = new svm_train(); svm_predict p = new svm_predict(); t.main(train_ops); p.main(test_ops); } }