Example usage for weka.core DenseInstance value

List of usage examples for weka.core DenseInstance value

Introduction

In this page you can find the example usage for weka.core DenseInstance value.

Prototype

@Override
publicdouble value(int attIndex) 

Source Link

Document

Returns an instance's attribute value in internal format.

Usage

From source file:naive_bayes.Naive_bayes.java

public double classifyInstance(Instances newData) throws Exception {
    DenseInstance newInstance = new DenseInstance(newData.instance(2));
    float[] prob = new float[newData.numClasses()];
    for (int i = 0; i < newData.numClasses(); i++) {

        prob[i] = (float) arrayOfClass[i].getCount() / (float) newData.numInstances();
        System.out.println("ii = " + prob[i]);

    }//  w  ww  .  j a v  a 2  s  .c  o  m

    for (int i = 0; i < newData.numClasses(); i++) {
        for (int j = 0; j < newData.numAttributes(); j++) {
            if (j != classidx) {
                System.out.println("j =" + j);
                double x = newInstance.value(j);
                System.out.println("x = " + x);
                int xx = (int) x;
                System.out.println("xx = " + xx);
                prob[i] *= M[j][i].get(xx).getCount();
                System.out.println("lala = " + prob[i]);
            }
        }
    }

    int indeksmaks = 0;
    double max = prob[indeksmaks];
    System.out.println("prob 0 = " + prob[0]);
    for (int i = 1; i < newData.numClasses(); i++) {
        if (max < prob[i]) {
            indeksmaks = i;
            max = prob[i];
            System.out.println("prob " + i + prob[i]);

        }
    }

    String tata = arrayOfClass[indeksmaks].getDisAttrName();
    System.out.println("kelas instance = " + tata);
    return indeksmaks;
}