Example usage for weka.core AbstractInstance setValue

List of usage examples for weka.core AbstractInstance setValue

Introduction

In this page you can find the example usage for weka.core AbstractInstance setValue.

Prototype

@Override
public final void setValue(Attribute att, String value) 

Source Link

Document

Sets a value of an nominal or string attribute to the given value.

Usage

From source file:meka.classifiers.multilabel.Evaluation.java

License:Open Source License

/**
 * TestClassifier - test classifier h on D_test
 * @param   h      a multi-dim. classifier, ALREADY BUILT
 * @param   D_test    test data/*  w  ww.  java  2s  .c  om*/
 * @return   Result   with raw prediction data ONLY
 */
public static Result testClassifier(MultiLabelClassifier h, Instances D_test) throws Exception {

    int L = D_test.classIndex();
    Result result = new Result(D_test.numInstances(), L);

    if (h.getDebug())
        System.out.print(":- Evaluate ");
    for (int i = 0, c = 0; i < D_test.numInstances(); i++) {

        if (h.getDebug()) {
            int t = i * 50 / D_test.numInstances();
            if (t > c) {
                System.out.print("#");
                c = t;
            }
        }

        // No cheating allowed; clear all class information
        AbstractInstance x = (AbstractInstance) ((AbstractInstance) D_test.instance(i)).copy();
        for (int v = 0; v < D_test.classIndex(); v++)
            x.setValue(v, 0.0);

        // Get and store ranking
        double y[] = h.distributionForInstance(x);
        // Cut off any [no-longer-needed] probabalistic information from MT classifiers.
        if (h instanceof MultiTargetClassifier)
            y = Arrays.copyOf(y, L);

        // Store the result
        result.addResult(y, D_test.instance(i));
    }
    if (h.getDebug())
        System.out.println(":-");

    /*
    if(h.getDebug()) {
            
       for(int i = 0; i < result.size(); i++) {
    System.out.println("\t"+Arrays.toString(result.rowTrue(i))+" vs "+Arrays.toString(result.rowRanking(i)));
       }
    }
    */

    return result;
}