Java 如何在 Weka 中使用 SVM?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18410900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use SVM in Weka?
提问by Shaayaan Sayed
I'm trying to use the svm classifier in weka. When I click on the libsvm classifier and try to train a model based on some provided training data, I get the error
我正在尝试在 weka 中使用 svm 分类器。当我单击 libsvm 分类器并尝试根据一些提供的训练数据训练模型时,出现错误
libsvm classes not in CLASSPATH.
The weka website has some information on how to fix this but I'm not sure how to execute them.
weka 网站有一些关于如何解决这个问题的信息,但我不确定如何执行它们。
http://weka.wikispaces.com/LibSVM
http://weka.wikispaces.com/LibSVM
I got the libsvm.jar file from the link provided. I'm not sure which file to put it in.
我从提供的链接中获得了 libsvm.jar 文件。我不确定将它放在哪个文件中。
回答by jaesanx
You have to set your classpath variable so it knows where to find that jar on your local machine.
您必须设置类路径变量,以便它知道在本地计算机上的何处可以找到该 jar。
If you are on windows right-click computer->properties->advanced system settings->environment variables and set it under system variables. Chances are you already have a classpath variable; so just add the path of your jar file to the end.
如果你在windows上右键计算机->属性->高级系统设置->环境变量,在系统变量下设置。您可能已经有一个类路径变量;所以只需将 jar 文件的路径添加到最后。
Reference: http://weka.wikispaces.com/CLASSPATH
回答by Sheetal Kaul
Adding to Rob's answer: suit your values as below. This is how it is saved for me.
添加到罗布的答案:适合您的价值观如下。这就是它为我保存的方式。
- Variable Name: CLASSPATH
- Variable value: C:\Program Files (x86)\Weka-3-6\libsvm-3.20\java\libsvm.jar
- 变量名称:CLASSPATH
- 变量值:C:\Program Files (x86)\Weka-3-6\libsvm-3.20\java\libsvm.jar
回答by Tharindu
You just need Libsvm.jar in the class path with latest versions of weka. Just try it like this
你只需要 Libsvm.jar 在最新版本的 weka 的类路径中。就这样试试
WekaPackageManager.loadPackages( false, true, false );
AbstractClassifier classifier = ( AbstractClassifier ) Class.forName(
"weka.classifiers.functions.LibSVM" ).newInstance();
If you prefer to give options set the options like this
如果您更喜欢提供选项,请设置如下选项
String options = ( "-S 0 -K 0 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 40.0 -C 1.0 -E 0.001 -P 0.1" );
String[] optionsArray = options.split( " " );
classifier.setOptions( optionsArray );
Finally train the classifier
最后训练分类器
classifier.buildClassifier( train );
回答by roopalgarg
In your .bash_profile file or in your environment variables you need to append the full path to the libsvm jar file For a .basch_profile file: export CLASSPATH=$CLASSPATH:/FULL_PATH_TO_LIBSVM.jar
在您的 .bash_profile 文件或环境变量中,您需要将完整路径附加到 libsvm jar 文件对于 .basch_profile 文件: export CLASSPATH=$CLASSPATH:/FULL_PATH_TO_LIBSVM.jar