Beispiel #1
0
  /**
   * Converts the tree under this node to a string
   *
   * @param treeLevel the depth of this node; the root of a tree should have treeLevel = 0
   * @param deviation the global deviation of the class column, used for evaluating relative errors
   * @return the converted string
   */
  public final String treeToString(int treeLevel, double deviation) {

    int i;
    StringBuffer text = new StringBuffer();

    if (type == true) {
      text.append("\n");
      for (i = 1; i <= treeLevel; i++) {
        text.append("    ");
      }
      if (itemsets.getAttribute(splitAttr).name().charAt(0) != '[') {
        text.append(
            itemsets.getAttribute(splitAttr).name()
                + " <= "
                + M5.doubleToStringG(splitValue, 1, 3)
                + " ");
      } else {
        text.append(itemsets.getAttribute(splitAttr).name() + " false : ");
      }
      treeLevel++;
      text.append(leftNode.treeToString(treeLevel, deviation));
      treeLevel--;
      for (i = 1; i <= treeLevel; i++) {
        text.append("    ");
      }
      if (itemsets.getAttribute(splitAttr).name().charAt(0) != '[') {
        text.append(
            itemsets.getAttribute(splitAttr).name()
                + " >  "
                + M5.doubleToStringG(splitValue, 1, 3)
                + " ");
      } else {
        text.append(itemsets.getAttribute(splitAttr).name() + " true : ");
      }
      treeLevel++;
      text.append(rightNode.treeToString(treeLevel, deviation));
      treeLevel--;
    } else { // LEAF
      text.append(" THEN LM" + lm + "\n");
      /*      if(deviation > 0.0)
      text.append(" (" + itemsets.numItemsets() + "/" +
           M5.doubleToStringG((100. * errors.rootMeanSqrErr /
               deviation),1,3) + "%)\n");
           else text.append(" (" + itemsets.numItemsets() + ")\n");*/
    }

    return text.toString();
  }
Beispiel #2
0
  /**
   * Converts the predictions by the tree under this node to a string
   *
   * @param inst itemsets
   * @param smooth =true using the smoothed models; otherwise, the unsmoothed
   * @param lmNo the number of the associated linear model
   * @return the converted string
   * @exception Exception if something goes wrong
   */
  public final String predictionsToString(MyDataset inst, int lmNo, boolean smooth)
      throws Exception {
    int i, lmNum;
    double value;
    StringBuffer text = new StringBuffer();

    text.append(
        "    Predicting test itemsets ("
            + inst.getAttribute(inst.getClassIndex()).name()
            + ", column "
            + (inst.getClassIndex() + 1)
            + ")\n\n");
    for (i = 0; i <= inst.numItemsets() - 1; i++) {
      lmNum = this.leafNum(inst.itemset(i));
      if (lmNo == 0 || lmNo == lmNum) {
        text.append("      Predicting " + i + " (LM" + lmNum + "):  ");
        text.append(inst.itemset(i).toString() + "\n");
        value = this.predict(inst.itemset(i), smooth);
        if (inst.itemset(i).classIsMissing() == false) {
          text.append(
              "      Actual value: "
                  + M5.doubleToStringG(inst.itemset(i).getClassValue(), 9, 4)
                  + "    Prediction: "
                  + M5.doubleToStringG(value, 9, 4)
                  + "    Abs. error: "
                  + M5.doubleToStringG(Math.abs(inst.itemset(i).getClassValue() - value), 9, 4)
                  + "\n\n");
        } else {
          text.append(
              "      Actual value:   missing    Prediction: "
                  + M5.doubleToStringG(value, 9, 4)
                  + "    Abs. Error: undefined\n\n");
        }
      }
    }

    return text.toString();
  }