本文介绍了SMO,WEKA中的顺序最小优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Weka的新手。我想在WEKA中使用顺序最小优化。
有人能告诉我怎么办吗?
这里是我的Java代码,但它不起作用:

I'm new with Weka. I want to use Sequential Minimal Optimization in WEKA.Could anyone tell me how to proceed?here is my Java code but it doesn't work:

public class SVMTest {
public void test(File input) throws Exception{
File tmp = new File("tmp-file-duplicate-pairs.arff");
String path = input.getParent();
//tmp.deleteOnExit();
////removeFeatures(input,tmp,useType,useNames, useActivities, useOccupation,useFriends,useMailAndSite,useLocations);
Instances data = new weka.core.converters.ConverterUtils.DataSource(tmp.getAbsolutePath()).getDataSet();
data.setClassIndex(data.numAttributes() - 1);
Classifier c = null;        
String ctype = null;
boolean newmodel = false;

ctype ="SMO";
c = new SMO();
String[] options = {"-M"};
c.setOptions(options);
c.buildClassifier(data);
newmodel = true;
//c = loadClassifier(input.getParentFile().getParentFile(),ctype);
if(newmodel)
    saveModel(c,ctype, input.getParentFile().getParentFile());
Evaluation eval = new Evaluation(data);
eval.crossValidateModel(c, data, 10, new Random(1));

System.out.println(c);
System.out.println(eval.toSummaryString());
System.out.println(eval.toClassDetailsString());
System.out.println(eval.toMatrixString());

tmp.delete();
}
 private static void saveModel(Classifier c, String name, File path) throws Exception {

ObjectOutputStream oos = null;
try {
    oos = new ObjectOutputStream(
            new FileOutputStream(path.getAbsolutePath()+"/"+name+".model"));
} catch (FileNotFoundException e1) {
    e1.printStackTrace();
} catch (IOException e1) {
    e1.printStackTrace();
}
oos.writeObject(c);
oos.flush();
oos.close();

 }
}

我想知道如何提供.arff文件?
我的数据集采用XML文件的形式。

I want to know how to provide .arff file?my Dataset is in the form of XML files.

推荐答案

我想你现在已经弄明白了,但是万一它有助于其他人,有一个关于它的维基页面:

I guess you have figured it out by now, but in case it helps others, there is a wiki page about it:

使用SMO,让我们说你有一些火车实例trainset,以及一个测试集testset
来构建分类器:

to use SMO, let's say you have some train instances "trainset", and a test set "testset"to build the classifier:

            // train SMO and output model
            SMO classifier = new SMO();
            classifier.buildClassifier(trainset);

使用交叉验证对其进行评估,例如:

to evaluate it using cross validation for example:

    Evaluation eval = new Evaluation(testset);
    Random rand = new Random(1); // using seed = 1
    int folds = 10;
    eval.crossValidateModel(classifier, testset, folds, rand);

然后eval保存所有统计数据等。

then eval holds all the stats, etc.

这篇关于SMO,WEKA中的顺序最小优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 06:54