/** 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(); }
/** 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"; }
/** * 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"; }
/** * 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(); } }
/** * Returns the number of rules (same as number of leaves) * * @return the number of rules */ public double measureNumRules() { return m_root.numLeaves(); }
/** * Returns the size of the tree * * @return the size of the tree */ public double measureTreeSize() { return m_root.numNodes(); }
/** * Returns tree in prefix order. * * @exception Exception if something goes wrong */ public String prefix() throws Exception { return m_root.prefix(); }
/** * Returns graph describing the tree. * * @exception Exception if graph can't be computed */ public String graph() throws Exception { return m_root.graph(); }
/** * 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); }
/** * Classifies an instance. * * @exception Exception if instance can't be classified successfully */ public double classifyInstance(Instance instance) throws Exception { return m_root.classifyInstance(instance); }