@Test
  public void testGenerateOutcomeIdPropertiesSingleLabel()
      throws ClassNotFoundException, IOException {
    List<String> labels = WekaUtils.getClassLabels(singleLabelData, false);
    Properties props =
        WekaOutcomeIDUsingTCEvaluationReport.generateProperties(
            singleLabelData, false, false, labels, null);
    String header = WekaOutcomeIDUsingTCEvaluationReport.generateHeader(labels);
    List<String> labelsFromProps = Id2Outcome.getLabels(header);

    assertTrue(header.split("\n")[1].startsWith("labels"));
    assertEquals(labels, labelsFromProps);
    assertEquals(16, props.size());

    assertEquals(0, Id2Outcome.classNamesToMapping(labelsFromProps).get("alt.atheism").intValue());
    assertEquals(
        3,
        Id2Outcome.classNamesToMapping(labelsFromProps).get("comp.sys.ibm.pc.hardware").intValue());
    assertEquals(
        2,
        Id2Outcome.classNamesToMapping(labelsFromProps).get("comp.os.ms-windows.misc").intValue());

    assertEquals(Arrays.asList(1.), getPrediction(props.getProperty("alt.atheism/53261.txt")));
    assertEquals(Arrays.asList(0), getGoldStandard(props.getProperty("alt.atheism/53261.txt")));
    assertEquals(
        Arrays.asList(1.), getPrediction(props.getProperty("comp.sys.ibm.pc.hardware/60738.txt")));
    assertEquals(
        Arrays.asList(3), getGoldStandard(props.getProperty("comp.sys.ibm.pc.hardware/60738.txt")));
    assertEquals(
        Arrays.asList(2.), getPrediction(props.getProperty("comp.os.ms-windows.misc/10006.txt")));
    assertEquals(
        Arrays.asList(2), getGoldStandard(props.getProperty("comp.os.ms-windows.misc/10006.txt")));
  }
  @Test
  public void testGenerateOutcomeIdPropertiesMultiLabel()
      throws ClassNotFoundException, IOException {
    List<String> labels = WekaUtils.getClassLabels(multiLabelData, true);
    Properties props =
        WekaOutcomeIDUsingTCEvaluationReport.generateProperties(
            multiLabelData, true, false, labels, mlResults);
    String header = WekaOutcomeIDUsingTCEvaluationReport.generateHeader(labels);
    List<String> labelsFromProps = Id2Outcome.getLabels(header);

    assertTrue(header.split("\n")[1].startsWith("labels"));
    assertEquals(labels, labelsFromProps);
    assertEquals(8, props.size());

    assertEquals(0, Id2Outcome.classNamesToMapping(labelsFromProps).get("__oat_Comp").intValue());
    assertEquals(2, Id2Outcome.classNamesToMapping(labelsFromProps).get("__crude_Comp").intValue());
    assertEquals(4, Id2Outcome.classNamesToMapping(labelsFromProps).get("__acq_Comp").intValue());

    assertEquals(1., getPrediction(props.getProperty("138.txt")).get(1), 0.1);
    assertEquals(Arrays.asList(0, 1, 0, 1, 0), getGoldStandard(props.getProperty("138.txt")));
    assertEquals(0., getPrediction(props.getProperty("151.txt")).get(0), 0.1);
    assertEquals(Arrays.asList(0, 0, 1, 0, 0), getGoldStandard(props.getProperty("151.txt")));
    assertEquals(0., getPrediction(props.getProperty("212.txt")).get(4), 0.1);
    assertEquals(Arrays.asList(0, 0, 0, 0, 1), getGoldStandard(props.getProperty("212.txt")));
  }
  @Before
  public void initialize() throws IOException {

    File singleLabelFile;
    File multiLabelFile;
    File regressionFile;
    try {
      singleLabelFile =
          new File(this.getClass().getResource("/predictions/singleLabelPredictions.arff").toURI());
      multiLabelFile =
          new File(this.getClass().getResource("/predictions/multiLabelPredictions.arff").toURI());
      regressionFile =
          new File(this.getClass().getResource("/predictions/regressionPredictions.arff").toURI());
      mlResults =
          new File(this.getClass().getResource("/predictions/multiLabelEvaluation.bin").toURI());
    } catch (URISyntaxException e) {
      throw new IOException(e);
    }

    singleLabelData = WekaUtils.getInstances(singleLabelFile, false);
    multiLabelData = WekaUtils.getInstances(multiLabelFile, true);
    regressionData = WekaUtils.getInstances(regressionFile, false);
  }
Esempio n. 4
0
 @Override
 public void write(
     File outputDirectory,
     FeatureStore featureStore,
     boolean useDenseInstances,
     String learningMode,
     boolean applyWeighting)
     throws Exception {
   WekaUtils.instanceListToArffFileMultiLabel(
       new File(
           outputDirectory,
           WekaClassificationAdapter.getInstance()
               .getFrameworkFilename(AdapterNameEntries.featureVectorsFile)),
       featureStore,
       useDenseInstances,
       applyWeighting);
 }