/** * 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(); }
/** * 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"; }
/** * 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"; }
/** * 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(); } }
/** * 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. * * @return the tree in prefix order * @throws Exception if something goes wrong */ public String prefix() throws Exception { return m_root.prefix(); }
/** * 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(); }
/** * 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); }
/** * 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); }