}   public OneRRule newRule(Attribute attr, Instances data) throws Exception {  OneRRule r;   int[] missingValueCounts = new int [data.classAttribute().numValues()];  if (attr.isNominal()) { r = newNominalRule(attr, data, missingValueCounts); } else { r = newNumericRule(attr, data, missingValueCounts); } r.m_missingValueClass = Utils.maxIndex(missingValueCounts); if (missingValueCounts[r.m_missingValueClass] == 0) { r.m_missingValueClass = -1; } else { r.m_correct += missingValueCounts[r.m_missingValueClass]; } return r; }   public OneRRule newNominalRule(Attribute attr, Instances data, int[] missingValueCounts) throws Exception {   int[][] counts = new int [attr.numValues()] [data.classAttribute().numValues()];   Enumeration enum = data.enumerateInstances(); while (enum.hasMoreElements()) { Instance i = (Instance) enum.nextElement(); if (i.isMissing(attr)) { missingValueCounts[(int) i.classValue()]++; } else { counts[(int) i.value(attr)][(int) i.classValue()]++; } }  OneRRule r = new OneRRule(data, attr); for (int value = 0; value < attr.numValues(); value++) { int best = Utils.maxIndex(counts[value]); r.m_classifications[value] = best; r.m_correct += counts[value][best]; }
  public void buildClassifier(Instances instances)     throws Exception {        boolean noRule = true;    if (instances.checkForStringAttributes()) {      throw new Exception("Can't handle string attributes!");    }    if (instances.classAttribute().isNumeric()) {      throw new Exception("Can't handle numeric class!");    }    Instances data = new Instances(instances);    // new dataset without missing class values    data.deleteWithMissingClass();    if (data.numInstances() == 0) {      throw new Exception("No instances with a class value!");    }    // for each attribute ...    Enumeration enum = instances.enumerateAttributes();    while (enum.hasMoreElements()) {      OneRRule r = newRule((Attribute) enum.nextElement(), data);      // if this attribute is the best so far, replace the rule      if (noRule || r.m_correct > m_rule.m_correct) {	m_rule = r;      }      noRule = false;    }