libsvm初识

来源:互联网 发布:淘宝u站 编辑:程序博客网 时间:2024/05/18 03:24

北京时间:2013/1/15    15:05

今天下午的任务是:将libsvm的java版本运行起来,并了解它的一些基本的参数及其用法。

let‘go.............

======================================================================================================================================

根据http://blog.csdn.net/yangliuy/article/details/8041343来操作的,感觉很不错哦!

1,先从http://www.csie.ntu.edu.tw/~cjlin/libsvm/index.html网站上下载libsvm

2,导入jar包libsvm.jar

3,将java下的svm—train.java和svm—predict.java导入到工程中去,做适当的修改。

在svm—train.java中

private static  String model_file_name;

并且main函数

public static String main(String argv[]) throws IOException
{
svm_train t = new svm_train();
t.run(argv);
return model_file_name;
}

在svm—predict.java中

加入private static Double accuracy;

并且main函数

public staticDouble main(String argv[]) throws IOException

而且main函数的最后要返回 return accracy;

修改完了之后就改写调用它们的函数了

public class svmTest
{
/**
* @param args
*/
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
String[] trainArgs = {"123"};//directory of training file
String modelFile = svm_train.main(trainArgs);
String[] testArgs ={"123", modelFile, "123out"}; //directory of test file, model file, result file
Double accuracy = svm_predict.main(testArgs);
System.out.println("SVM Classification is done! The accuracy is " + accuracy);
}
}

好了,以上就是将java版本的svm跑起来的过程了,不过用它是好用,但是关键是做前期他所需要的格式,什么的很麻烦的。。。不过还留了个小的疑问,就是我用的是bool类型的,但是最后返回的是

0.0
0.0
0.0
0.0
0.0
-1.0
0.0
-1.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
-1.0
0.0
0.0
0.0

我想在程序中就可以返回int类型的,这个问题还没有解决,不知道怎么办?继续努力吧!革命还未完成同志仍需努力!!

原创粉丝点击