Example usage for weka.filters.unsupervised.instance RemoveWithValues setNominalIndices

List of usage examples for weka.filters.unsupervised.instance RemoveWithValues setNominalIndices

Introduction

In this page you can find the example usage for weka.filters.unsupervised.instance RemoveWithValues setNominalIndices.

Prototype

public void setNominalIndices(String rangeList) 

Source Link

Document

Set which nominal labels are to be included in the selection.

Usage

From source file:wekimini.DataManager.java

private void updateInstancesForNewLowerMaxClass(int index, int newNumClasses) {
    //Change allInstances, dummyInstances
    // dummyInstances.attribute(numMetaData + numInputs + index).

    RemoveWithValues r = new RemoveWithValues();
    String rangeList = "1-" + (newNumClasses + 1); //String indices start at 1 in weka

    Instances newAll;/*from  w w  w . jav  a2  s.c  o  m*/
    try {
        r.setAttributeIndex(Integer.toString(numMetaData + numInputs + index + 1)); //Weka indexing stupidity
        r.setNominalIndices(rangeList);
        r.setInvertSelection(true); //Keep all classes from 0 to newNumClasses
        r.setMatchMissingValues(false);
        r.setModifyHeader(true);
        r.setInputFormat(allInstances);

        newAll = Filter.useFilter(allInstances, r);
    } catch (Exception ex) {
        Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    if (newAll.numInstances() != allInstances.numInstances()) {
        logger.log(Level.SEVERE, "Problem: deleted instances when removing class attribute");
    }
    allInstances = newAll;

    Instances newD;
    try {
        newD = Filter.useFilter(dummyInstances, r);
    } catch (Exception ex) {
        Logger.getLogger(DataManager.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }

    dummyInstances = newD;
}