Example usage for weka.classifiers.trees J48 distributionForInstance

List of usage examples for weka.classifiers.trees J48 distributionForInstance

Introduction

In this page you can find the example usage for weka.classifiers.trees J48 distributionForInstance.

Prototype

@Override
public final double[] distributionForInstance(Instance instance) throws Exception 

Source Link

Document

Returns class probabilities for an instance.

Usage

From source file:probcog.J48Reader.java

License:Open Source License

public static void main(String[] args) {
    try {/*from ww w . jav  a 2s  .  co  m*/
        String path = "./";
        //String dbdir = path + "zoli4uli4";
        String dbdir = path + args[1];
        J48 j48 = readJ48(dbdir);
        Instances instances = readDB(args[0]);
        //System.out.println(j48.toString());
        for (int i = 0; i < instances.numInstances(); i++) {
            Instance inst = instances.instance(i);
            //System.out.println(instances.toString());
            /*
            double d = j48.classifyInstance(inst);
            System.out.println(inst.attribute(inst.classIndex()).toString());
            inst.setValue(inst.attribute(inst.classIndex()),d);
            System.out.println("Object is classified as "+ inst.toString(inst.attribute(inst.classIndex())));
            */
            //System.out.println(inst);
            double dist[] = j48.distributionForInstance(inst);
            int j = 0;
            for (double d : dist) {
                Attribute att = instances.attribute(instances.classIndex());
                String classification = att.value(j);
                System.out.println(d + "  " + classification);
                j++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}