use weka classifiers trees LMT - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

use weka classifiers trees LMT

Demo Code

import weka.classifiers.Evaluation;
import weka.classifiers.functions.SMO;
import weka.classifiers.meta.Bagging;
import weka.classifiers.meta.CVParameterSelection;
import weka.classifiers.meta.Dagging;
import weka.classifiers.trees.RandomForest;
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class UntunedRF {

    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);
        Bagging vs = new Bagging();

        vs.setOptions(weka.core.Utils/* ww w.  j  a  v a  2s  .  com*/
                .splitOptions("-P 100 -S 1 -I 10 -W \"weka.classifiers.trees.LMT\""));
        vs.buildClassifier(train);
        PrintWriter pw = new PrintWriter(new FileWriter(
                "sonar-L5.txt"));

        for (int i = 0; i < test.numInstances(); i++) {
            double pred = vs.classifyInstance(test.instance(i));
            pw.println(pred);
        }
        pw.close();
        Evaluation eval = new Evaluation(train);
        eval.evaluateModel(vs, test);
        Double error_c = eval.errorRate();
        System.out.println(error_c);

    }
}

Related Tutorials