Пример #1
0
  /** Returns a description of the classifier. */
  public String toString() {

    if (m_root == null) {
      return "No classifier built";
    }
    if (m_unpruned) return "J48 unpruned tree\n------------------\n" + m_root.toString();
    else return "J48 pruned tree\n------------------\n" + m_root.toString();
  }
Пример #2
0
  /** Returns a superconcise version of the model */
  public String toSummaryString() {

    return "Number of leaves: "
        + m_root.numLeaves()
        + "\n"
        + "Size of the tree: "
        + m_root.numNodes()
        + "\n";
  }
Пример #3
0
  /**
   * Returns tree as an if-then statement.
   *
   * @return the tree as a Java if-then type statement
   * @exception Exception if something goes wrong
   */
  public String toSource(String className) throws Exception {

    StringBuffer[] source = m_root.toSource(className);
    return "class "
        + className
        + " {\n\n"
        + "  public static double classify(Object [] i)\n"
        + "    throws Exception {\n\n"
        + "    double p = Double.NaN;\n"
        + source[0] // Assignment code
        + "    return p;\n"
        + "  }\n"
        + source[1] // Support code
        + "}\n";
  }
Пример #4
0
  /**
   * Generates the classifier.
   *
   * @exception Exception if classifier can't be built successfully
   */
  public void buildClassifier(Instances instances) throws Exception {

    ModelSelection modSelection;

    if (m_binarySplits) modSelection = new BinC45ModelSelection(m_minNumObj, instances);
    else modSelection = new C45ModelSelection(m_minNumObj, instances);
    if (!m_reducedErrorPruning)
      m_root =
          new C45PruneableClassifierTree(
              modSelection, !m_unpruned, m_CF, m_subtreeRaising, !m_noCleanup);
    else m_root = new PruneableClassifierTree(modSelection, !m_unpruned, m_numFolds, !m_noCleanup);
    m_root.buildClassifier(instances);
    if (m_binarySplits) {
      ((BinC45ModelSelection) modSelection).cleanup();
    } else {
      ((C45ModelSelection) modSelection).cleanup();
    }
  }
Пример #5
0
 /**
  * Returns the number of rules (same as number of leaves)
  *
  * @return the number of rules
  */
 public double measureNumRules() {
   return m_root.numLeaves();
 }
Пример #6
0
 /**
  * Returns the size of the tree
  *
  * @return the size of the tree
  */
 public double measureTreeSize() {
   return m_root.numNodes();
 }
Пример #7
0
  /**
   * Returns tree in prefix order.
   *
   * @exception Exception if something goes wrong
   */
  public String prefix() throws Exception {

    return m_root.prefix();
  }
Пример #8
0
  /**
   * Returns graph describing the tree.
   *
   * @exception Exception if graph can't be computed
   */
  public String graph() throws Exception {

    return m_root.graph();
  }
Пример #9
0
  /**
   * Returns class probabilities for an instance.
   *
   * @exception Exception if distribution can't be computed successfully
   */
  public final double[] distributionForInstance(Instance instance) throws Exception {

    return m_root.distributionForInstance(instance, m_useLaplace);
  }
Пример #10
0
  /**
   * Classifies an instance.
   *
   * @exception Exception if instance can't be classified successfully
   */
  public double classifyInstance(Instance instance) throws Exception {

    return m_root.classifyInstance(instance);
  }