public static void instanceListToArffFileMultiLabel(File outputFile,FeatureStore featureStore,boolean useDenseInstances,boolean useWeights) throws Exception {
  AttributeStore attributeStore=WekaFeatureEncoder.getAttributeStore(featureStore);
  List<Attribute> outcomeAttributes=createOutcomeAttributes(new ArrayList<String>(featureStore.getUniqueOutcomes()));
  for (  Attribute attribute : outcomeAttributes) {
    attributeStore.addAttributeAtBegin(attribute.name(),attribute);
  }
  Instances wekaInstances=new Instances(RELATION_NAME + ": -C " + outcomeAttributes.size()+ " ",attributeStore.getAttributes(),featureStore.getNumberOfInstances());
  wekaInstances.setClassIndex(outcomeAttributes.size());
  if (!outputFile.exists()) {
    outputFile.mkdirs();
    outputFile.createNewFile();
  }
  ArffSaver saver=new ArffSaver();
  saver.setRetrieval(Saver.INCREMENTAL);
  saver.setFile(outputFile);
  saver.setCompressOutput(true);
  saver.setInstances(wekaInstances);
  for (int i=0; i < featureStore.getNumberOfInstances(); i++) {
    Instance instance=featureStore.getInstance(i);
    double[] featureValues=getFeatureValues(attributeStore,instance);
    List<String> instanceOutcome=instance.getOutcomes();
    for (    Attribute label : outcomeAttributes) {
      String labelname=label.name();
      featureValues[attributeStore.getAttributeOffset(labelname)]=instanceOutcome.contains(labelname.split(CLASS_ATTRIBUTE_PREFIX)[1]) ? 1.0d : 0.0d;
    }
    weka.core.Instance wekaInstance;
    if (useDenseInstances) {
      wekaInstance=new DenseInstance(1.0,featureValues);
    }
 else {
      wekaInstance=new SparseInstance(1.0,featureValues);
    }
    wekaInstance.setDataset(wekaInstances);
    Double instanceWeight=featureStore.getWeight(i);
    if (useWeights) {
      wekaInstance.setWeight(instanceWeight);
    }
    saver.writeIncremental(wekaInstance);
  }
  saver.writeIncremental(null);
}

public static void instanceListToArffFileMultiLabel ( File outputFile , FeatureStore featureStore , boolean useDenseInstances , boolean useWeights ) throws Exception { AttributeStore attributeStore = WekaFeatureEncoder . getAttributeStore ( featureStore ) ; List < Attribute > outcomeAttributes = createOutcomeAttributes ( new ArrayList < String > ( featureStore . getUniqueOutcomes ( ) ) ) ; for ( Attribute attribute : outcomeAttributes ) { attributeStore . addAttributeAtBegin ( attribute . name ( ) , attribute ) ; } Instances wekaInstances = new Instances ( RELATION_NAME + ": -C " + outcomeAttributes . size ( ) + " " , attributeStore . getAttributes ( ) , featureStore . getNumberOfInstances ( ) ) ; wekaInstances . setClassIndex ( outcomeAttributes . size ( ) ) ; if ( ! outputFile . exists ( ) ) { outputFile . mkdirs ( ) ; outputFile . createNewFile ( ) ; } ArffSaver saver = new ArffSaver ( ) ; saver . setRetrieval ( Saver . INCREMENTAL ) ; saver . setFile ( outputFile ) ; saver . setCompressOutput ( true ) ; saver . setInstances ( wekaInstances ) ; for ( int i = 0 ; i < featureStore . getNumberOfInstances ( ) ; i ++ ) { Instance instance = featureStore . getInstance ( i ) ; double [ ] featureValues = getFeatureValues ( attributeStore , instance ) ; List < String > instanceOutcome = instance . getOutcomes ( ) ; for ( Attribute label : outcomeAttributes ) { String labelname = label . name ( ) ; featureValues [ attributeStore . getAttributeOffset ( labelname ) ] = instanceOutcome . contains ( labelname . split ( CLASS_ATTRIBUTE_PREFIX ) [ 1 ] ) ? 1.0d : 0.0d ; } weka . core . Instance wekaInstance ; if ( useDenseInstances ) { wekaInstance = new DenseInstance ( 1.0 , featureValues ) ; } else { wekaInstance = new SparseInstance ( 1.0 , featureValues ) ; } wekaInstance . setDataset ( wekaInstances ) ; Double instanceWeight = featureStore . getWeight ( i ) ; if ( useWeights ) { wekaInstance . setWeight ( instanceWeight ) ; } saver . writeIncremental ( wekaInstance ) ; } saver . writeIncremental ( null ) ; }
converts a feature store to a list of instances . multi - label case .
