我正在尝试将LibSVM与Weka API一起使用.
我的系统:Win7 Weka 3.7.12 LibSVM 1.0.6(通过软件包管理器安装)
我的代码:
import java.io.File;
import java.util.Random;
import javax.swing.JOptionPane;
import weka.classifiers.Evaluation;
import weka.classifiers.functions.LibSVM;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
public class LibSVMClassifier {
// Method to build a SVM classifier with a given data file
public static double buildModel(File dataSet){
// new instance of LibSVM
LibSVM clsSVM = new LibSVM();
try {
Instances data = DataSource.read(dataSet.getAbsolutePath());
// Sets the label feature
data.setClassIndex(data.numAttributes()-1);
String opts = "-S 0 -K 0 -D 3 -G 0.0 -R 0.0 -N 0.5 …Run Code Online (Sandbox Code Playgroud)