use weka classifiers trees NBTree - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

use weka classifiers trees NBTree

Demo Code

import weka.classifiers.trees.NBTree;
import weka.core.Instances;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class UntunedNBTree {

    public static void main(String[] args) throws Exception {
        // load data sets
        Instances train = new Instances(new BufferedReader(new FileReader(
                "spambase_train.arff")));
        Instances test = new Instances(new BufferedReader(new FileReader(
                "spambase_test.arff")));
        train.setClassIndex(train.numAttributes() - 1);
        test.setClassIndex(test.numAttributes() - 1);
        NBTree vs = new NBTree();

        vs.buildClassifier(train);//from www.j a  v  a2  s .  co  m
        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