Example usage for weka.classifiers.trees M5P graph

List of usage examples for weka.classifiers.trees M5P graph

Introduction

In this page you can find the example usage for weka.classifiers.trees M5P graph.

Prototype

@Override
public String graph() throws Exception 

Source Link

Document

Return a dot style String describing the tree.

Usage

From source file:lu.lippmann.cdb.dt.ModelTreeFactory.java

License:Open Source License

/**
 * Main method./*from w ww.  j a  v a  2s.  c om*/
 * @param args command line arguments
 */
public static void main(final String[] args) {
    try {
        //final String f="./samples/csv/uci/winequality-red-simplified.csv";
        final String f = "./samples/csv/uci/winequality-white.csv";
        //final String f="./samples/arff/UCI/crimepredict.arff";
        final Instances dataSet = WekaDataAccessUtil.loadInstancesFromARFFOrCSVFile(new File(f));
        System.out.println(dataSet.classAttribute().isNumeric());

        final M5P rt = new M5P();
        //rt.setUnpruned(true);
        rt.setMinNumInstances(1000);
        rt.buildClassifier(dataSet);

        System.out.println(rt);

        System.out.println(rt.graph());

        final GraphWithOperations gwo = GraphUtil.buildGraphWithOperationsFromWekaRegressionString(rt.graph());
        System.out.println(gwo);
        System.out.println(new ASCIIGraphDsl().getDslString(gwo));

        final Evaluation eval = new Evaluation(dataSet);

        /*Field privateStringField = Evaluation.class.getDeclaredField("m_CoverageStatisticsAvailable");
        privateStringField.setAccessible(true);
        //privateStringField.get
        boolean fieldValue = privateStringField.getBoolean(eval);
        System.out.println("fieldValue = " + fieldValue);*/

        double[] d = eval.evaluateModel(rt, dataSet);
        System.out.println("PREDICTED -> " + FormatterUtil.buildStringFromArrayOfDoubles(d));

        System.out.println(eval.errorRate());
        System.out.println(eval.sizeOfPredictedRegions());

        System.out.println(eval.toSummaryString("", true));

        System.out.println(new DecisionTree(gwo, eval.errorRate()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}