示例#1
0
  /**
   * Returns a description of the classifier.
   *
   * @return 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
   *
   * @return a summary 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.
   *
   * @param className the name of the Java class
   * @return the tree as a Java if-then type statement
   * @throws 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.
   *
   * @param instances the data to train the classifier with
   * @throws 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, m_useMDLcorrection);
    else modSelection = new C45ModelSelection(m_minNumObj, instances, m_useMDLcorrection);
    if (!m_reducedErrorPruning)
      m_root =
          new C45PruneableClassifierTree(
              modSelection, !m_unpruned, m_CF, m_subtreeRaising, !m_noCleanup, m_collapseTree);
    else
      m_root =
          new PruneableClassifierTree(modSelection, !m_unpruned, m_numFolds, !m_noCleanup, m_Seed);
    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.
   *
   * @return the tree in prefix order
   * @throws Exception if something goes wrong
   */
  public String prefix() throws Exception {

    return m_root.prefix();
  }
示例#8
0
  /**
   * Returns graph describing the tree.
   *
   * @return the graph describing the tree
   * @throws Exception if graph can't be computed
   */
  public String graph() throws Exception {

    return m_root.graph();
  }
示例#9
0
  /**
   * Returns class probabilities for an instance.
   *
   * @param instance the instance to calculate the class probabilities for
   * @return the class probabilities
   * @throws 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.
   *
   * @param instance the instance to classify
   * @return the classification for the instance
   * @throws Exception if instance can't be classified successfully
   */
  public double classifyInstance(Instance instance) throws Exception {

    return m_root.classifyInstance(instance);
  }