gpt4 book ai didi

java - SMO,WEKA 中的顺序最小优化

转载 作者:太空宇宙 更新时间:2023-11-04 08:21:32 28 4
gpt4 key购买 nike

我是 Weka 的新手。我想在 WEKA 中使用顺序最小优化。谁能告诉我如何继续?这是我的 Java 代码,但它不起作用:

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文件的形式。

最佳答案

我想你现在已经明白了,但如果它对其他人有帮助,有一个关于它的 wiki 页面:

http://weka.wikispaces.com/Text+categorization+with+WEKA

要使用 SMO,假设您有一些火车实例“trainset”和一个测试集“testset”构建分类器:

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

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

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

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

关于java - SMO,WEKA 中的顺序最小优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9451651/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com