예제 #1
0
  @Override
  public void estimatePerformance(ExampleSet inputSet) throws OperatorException {
    // split by attribute
    Attribute batchAttribute = inputSet.getAttributes().getSpecial(Attributes.BATCH_NAME);
    if (batchAttribute == null) {
      throw new UserError(this, 113, Attributes.BATCH_NAME);
    }
    SplittedExampleSet splittedES = SplittedExampleSet.splitByAttribute(inputSet, batchAttribute);

    // start crossvalidation
    for (iteration = 0; iteration < splittedES.getNumberOfSubsets(); iteration++) {

      splittedES.selectAllSubsetsBut(iteration);
      learn(splittedES);

      splittedES.selectSingleSubset(iteration);
      evaluate(splittedES);

      inApplyLoop();
    }
    // end crossvalidation
  }
  private RuleModel createNominalRuleModel(ExampleSet exampleSet, Attribute attribute) {
    RuleModel model = new RuleModel(exampleSet);
    SplittedExampleSet splittedSet = SplittedExampleSet.splitByAttribute(exampleSet, attribute);
    Attribute label = splittedSet.getAttributes().getLabel();
    for (int i = 0; i < splittedSet.getNumberOfSubsets(); i++) {
      splittedSet.selectSingleSubset(i);
      splittedSet.recalculateAttributeStatistics(label);
      SplitCondition term =
          new NominalSplitCondition(attribute, attribute.getMapping().mapIndex(i));

      int labelValue = (int) splittedSet.getStatistics(label, Statistics.MODE);
      String labelName = label.getMapping().mapIndex(labelValue);
      Rule rule = new Rule(labelName, term);

      int[] frequencies = new int[label.getMapping().size()];
      int counter = 0;
      for (String value : label.getMapping().getValues())
        frequencies[counter++] = (int) splittedSet.getStatistics(label, Statistics.COUNT, value);
      rule.setFrequencies(frequencies);
      model.addRule(rule);
    }
    return model;
  }