Remove attributeFilter = new Remove(); attributeFilter.setAttributeIndicesArray(finalAttsToDelete); attributeFilter.setInvertSelection(false); attributeFilter.setInputFormat(toFilter);  for (int i = 0; i < toFilter.numInstances(); i++) { attributeFilter.input(toFilter.instance(i)); } attributeFilter.batchFinished();  Instance processed; Instances outputDataset = attributeFilter.getOutputFormat();   outputDataset.setRelationName(toFilter.relationName());  setOutputFormat(outputDataset); while ((processed = attributeFilter.output()) != null) { processed.setDataset(outputDataset); push(processed); }  flushInput();
  public boolean batchFinished() throws Exception {    if (getInputFormat() == null) {      throw new IllegalStateException("No input instance format defined");    }    // do filtering here    Instances toFilter = getInputFormat();    int[] attsToDelete = new int[toFilter.numAttributes()];    int numToDelete = 0;    for(int i = 0; i < toFilter.numAttributes(); i++) {      AttributeStats stats = toFilter.attributeStats(i);      if (stats.distinctCount < 2) {	// remove constant attributes	attsToDelete[numToDelete++] = i;      } else {	// remove attributes that vary too much	double variancePercent = (double) stats.distinctCount	  / (double) stats.totalCount * 100.0;	if (variancePercent > m_maxVariancePercentage) attsToDelete[numToDelete++] = i;      }    }    int[] finalAttsToDelete = new int[numToDelete];    System.arraycopy(attsToDelete, 0, finalAttsToDelete, 0, numToDelete);        Remove attributeFilter = new Remove();    attributeFilter.setAttributeIndicesArray(finalAttsToDelete);    attributeFilter.setInvertSelection(false);    attributeFilter.setInputFormat(toFilter);        for (int i = 0; i < toFilter.numInstances(); i++) {      attributeFilter.input(toFilter.instance(i));    }    attributeFilter.batchFinished();    Instance processed;    Instances outputDataset = attributeFilter.getOutputFormat();        // restore old relation name to hide attribute filter stamp    outputDataset.setRelationName(toFilter.relationName());        setOutputFormat(outputDataset);    while ((processed = attributeFilter.output()) != null) {      processed.setDataset(outputDataset);      push(processed);    }    flushInput();    m_NewBatch = true;    return (numPendingOutput() != 0);  }