问题描述
我想在我的应用程序中使用带有Weka的LibSVM分类器。我怎么能(或者我在哪里可以找到好的例子)这样做?
I want to use LibSVM classifier with Weka in my application. How can I (or where can I find good examples to) do this?
推荐答案
现在有点晚了,当然,但我无论如何都会回答。您必须在项目中使用weka.jar,libsvm.jar和wlsvm.jar(libsvm包装器)。所以只需在构建路径或类路径中包含所有3个jar或其他任何内容。
A little late now, surely, but I'll answer anyways. You have to use weka.jar, libsvm.jar, and wlsvm.jar (the libsvm wrapper) in your project. So just include all 3 jars in your build path or class path or whatever.
你可以从这里得到wlsvm.jar:
You can get the wlsvm.jar from here: http://www.cs.iastate.edu/~yasser/wlsvm/
您可以从这里获得weka:
You can get weka from here: http://www.cs.waikato.ac.nz/ml/weka/
你可以从这里获得libsvm:
And you can get libsvm from here: http://www.csie.ntu.edu.tw/~cjlin/libsvm/
我无法与weka合作3.7.7或3.7.8,但我能够使用3.6.8(截至今天的最新稳定版本)。
I could not get this to work with weka 3.7.7 or 3.7.8, but I was able to get it working with 3.6.8 (latest stable version as of today).
另外,因为我不得不从svnlib获取.class文件,并在我的项目的构建路径中包含那些文件。要构建.class文件,请使用SVNLib / java中的make文件。
Also, as I had to get the .class files from the svnlib and also include those in the build path to my project. To build the .class files, use the make file in the SVNLib/java.
这里有一小段代码可以帮助您入门:
Here is a small piece of code to get you started:
DataSource source = new DataSource(new File("mycsvinputfile"));
System.out.println(source.getStructure());
Instances data = source.getDataSet();
// setting class attribute if the data format does not provide this information
// For example, the XRFF format saves the class attribute information as well
if (data.classIndex() == -1)
data.setClassIndex(data.numAttributes() - 1);
//initialize svm classifier
LibSVM svm = new LibSVM();
svm.buildClassifier(data);
祝你好运。
这篇关于如何在我的Java代码中使用LibSVM和Weka?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!