Example usage for weka.core Instances meanOrMode

List of usage examples for weka.core Instances meanOrMode

Introduction

In this page you can find the example usage for weka.core Instances meanOrMode.

Prototype

publicdouble meanOrMode(Attribute att) 

Source Link

Document

Returns the mean (mode) for a numeric (nominal) attribute as a floating-point value.

Usage

From source file:transformation.mimlTOml.ArithmeticTransformation.java

License:Open Source License

@Override
public Instance transformInstance(Bag bag) throws Exception {

    int labelIndices[] = dataset.getLabelIndices();
    Instance newInst = new DenseInstance(template.numAttributes());

    // sets the bagLabel
    newInst.setDataset(bag.dataset()); // Sets the reference to the dataset
    newInst.setValue(0, bag.value(0));//w w w  . j  a  v a 2  s.  c  om

    // retrieves instances (relational value)
    Instances instances = bag.getBagAsInstances();
    // For all attributes in bag
    for (int j = 0, attIdx = 1; j < instances.numAttributes(); j++, attIdx++) {
        double value = instances.meanOrMode(j);
        newInst.setValue(attIdx, value);
    }

    // Insert label information into the instance
    for (int j = 0; j < labelIndices.length; j++) {
        newInst.setValue(updatedLabelIndices[j], bag.value(labelIndices[j]));
    }

    return newInst;
}