Example usage for weka.classifiers.trees J48 measureNumRules

List of usage examples for weka.classifiers.trees J48 measureNumRules

Introduction

In this page you can find the example usage for weka.classifiers.trees J48 measureNumRules.

Prototype

public double measureNumRules() 

Source Link

Document

Returns the number of rules (same as number of leaves)

Usage

From source file:meddle.TrainModelByDomainOS.java

License:Open Source License

/**
 * Given a classifier model, print out the tree graph and its html report.
 *
 * @param j48//ww  w  .j  a  v a 2  s  . c  o m
 *            - the classifier model
 * @param domainOS
 *            - domain,os name
 * @param mem
 *            - the measurement results
 * */
public static void doGraphicOutput(J48 j48, String domainOS, MetaEvaluationMeasures mem) {
    try {

        String on = RConfig.dtGraphFolder + domainOS + ".dot";
        String png = RConfig.dtGraphFolder + domainOS + ".png";
        BufferedWriter bw = new BufferedWriter(new FileWriter(on));
        bw.write(j48.graph());
        bw.close();

        String sum = "<h3>" + mem.info.domain + "(" + mem.info.OS + ")</h3>\n";
        sum += "Accuracy: " + mem.accuracy + "<br/> \n";
        sum += "AUC: " + mem.AUC + "<br/> \n";
        sum += "False Positive Rate: " + mem.falsePositiveRate + "<br/> \n";
        sum += "False Negative Rate: " + mem.falseNegativeRate + "<br/> <br/> \n";

        sum += "Initial Number of Samples: " + mem.info.initNumTotal + "<br/>\n";
        sum += "Initial Number of Positive: " + mem.info.initNumPos + "<br/>\n";
        sum += "Initial Number of Negative: " + mem.info.initNumNeg + "<br/><br/>\n";
        sum += ">>> After balancing ...<br/> \n";
        sum += "Trained Number of Samples: " + mem.numTotal + "<br/>\n";
        sum += "Trained Number of Positive: " + mem.numPositive + "<br/>\n";
        sum += "Trained Number of Negative: " + mem.numNegative + "<br/></br/>\n";

        sum += "<img src='" + domainOS + ".png'/><br/> <br/> \n";
        sum += j48.toString().replace("\n", "<br/>");
        sum += "Number of Rules: " + j48.measureNumRules() + "<br/>\n";
        sum += "<a href='../domain_os/" + mem.info.fileNameRelative + "'>training data</a>";

        sum = "<html><body>" + sum;
        sum += "</body></html>";
        String cmd = RConfig.DOT_PATH + " -o " + png + " " + on + " -Tpng";
        // http://www.graphviz.org/content/output-formats#ddot
        // need to install graphviz tool
        // Mac OX: brew install graphviz
        // Ubuntu: sudo apt-get install graphviz
        String html = RConfig.dtGraphFolder + domainOS + ".html";
        bw = new BufferedWriter(new FileWriter(html));
        bw.write(sum);
        bw.close();
        Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

}