Use weka classifiers functions SMO - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

Use weka classifiers functions SMO

Demo Code

import weka.classifiers.functions.SMO;
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class UntunedSMO {

    public static void main(String[] args) throws Exception {
        Instances train = new Instances(new BufferedReader(new FileReader(
                "sonar_train.arff")));
        Instances test = new Instances(new BufferedReader(new FileReader(
                "sonar_test.arff")));
        train.setClassIndex(train.numAttributes() - 1);
        test.setClassIndex(test.numAttributes() - 1);
        SMO vs = new SMO();
        vs.buildClassifier(train);/*from w  ww.j a  v  a 2  s.c om*/
        PrintWriter pw = new PrintWriter(new FileWriter(
                "spambase-LB.txt"));

        for (int i = 0; i < test.numInstances(); i++) {
            double pred = vs.classifyInstance(test.instance(i));
            pw.println(pred);
        }
        pw.close();
    }
}

Related Tutorials