Example usage for weka.classifiers.trees REPTree setNoPruning

List of usage examples for weka.classifiers.trees REPTree setNoPruning

Introduction

In this page you can find the example usage for weka.classifiers.trees REPTree setNoPruning.

Prototype

public void setNoPruning(boolean newNoPruning) 

Source Link

Document

Set the value of NoPruning.

Usage

From source file:lu.lippmann.cdb.datasetview.tabs.RegressionTreeTabView.java

License:Open Source License

/**
 * {@inheritDoc}/* w  ww  .jav  a 2  s .c  om*/
 */
@SuppressWarnings("unchecked")
@Override
public void update0(final Instances dataSet) throws Exception {
    this.panel.removeAll();

    //final Object[] attrNames=WekaDataStatsUtil.getNumericAttributesNames(dataSet).toArray();
    final Object[] attrNames = WekaDataStatsUtil.getAttributeNames(dataSet).toArray();
    final JComboBox xCombo = new JComboBox(attrNames);
    xCombo.setBorder(new TitledBorder("Attribute to evaluate"));

    final JXPanel comboPanel = new JXPanel();
    comboPanel.setLayout(new GridLayout(1, 2));
    comboPanel.add(xCombo);
    final JXButton jxb = new JXButton("Compute");
    comboPanel.add(jxb);
    this.panel.add(comboPanel, BorderLayout.NORTH);

    jxb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (gv != null)
                    panel.remove((Component) gv);

                dataSet.setClassIndex(xCombo.getSelectedIndex());

                final REPTree rt = new REPTree();
                rt.setNoPruning(true);
                //rt.setMaxDepth(3);
                rt.buildClassifier(dataSet);

                /*final M5P rt=new M5P();
                rt.buildClassifier(dataSet);*/

                final Evaluation eval = new Evaluation(dataSet);
                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));

                final GraphWithOperations gwo = GraphUtil
                        .buildGraphWithOperationsFromWekaRegressionString(rt.graph());
                final DecisionTree dt = new DecisionTree(gwo, eval.errorRate());

                gv = DecisionTreeToGraphViewHelper.buildGraphView(dt, eventPublisher, commandDispatcher);
                gv.addMetaInfo("Size=" + dt.getSize(), "");
                gv.addMetaInfo("Depth=" + dt.getDepth(), "");

                gv.addMetaInfo("MAE=" + FormatterUtil.DECIMAL_FORMAT.format(eval.meanAbsoluteError()) + "", "");
                gv.addMetaInfo("RMSE=" + FormatterUtil.DECIMAL_FORMAT.format(eval.rootMeanSquaredError()) + "",
                        "");

                final JCheckBox toggleDecisionTreeDetails = new JCheckBox("Toggle details");
                toggleDecisionTreeDetails.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (!tweakedGraph) {
                            final Object[] mapRep = WekaDataStatsUtil
                                    .buildNodeAndEdgeRepartitionMap(dt.getGraphWithOperations(), dataSet);
                            gv.updateVertexShapeTransformer((Map<CNode, Map<Object, Integer>>) mapRep[0]);
                            gv.updateEdgeShapeRenderer((Map<CEdge, Float>) mapRep[1]);
                        } else {
                            gv.resetVertexAndEdgeShape();
                        }
                        tweakedGraph = !tweakedGraph;
                    }
                });
                gv.addMetaInfoComponent(toggleDecisionTreeDetails);

                /*final JButton openInEditorButton = new JButton("Open in editor");
                openInEditorButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                       GraphUtil.importDecisionTreeInEditor(dtFactory, dataSet, applicationContext, eventPublisher, commandDispatcher);
                   }
                });
                this.gv.addMetaInfoComponent(openInEditorButton);*/

                final JButton showTextButton = new JButton("In text");
                showTextButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        JOptionPane.showMessageDialog(null, graphDsl.getDslString(dt.getGraphWithOperations()));
                    }
                });
                gv.addMetaInfoComponent(showTextButton);

                panel.add(gv.asComponent(), BorderLayout.CENTER);
            } catch (Exception e1) {
                e1.printStackTrace();
                panel.add(new JXLabel("Error during computation: " + e1.getMessage()), BorderLayout.CENTER);
            }

        }
    });
}

From source file:statechum.analysis.learning.experiments.PaperUAS.java

License:Open Source License

/** Used to training a few different classifiers from a full PTA by comparing metrics on pairs considered by QSM and checking them against the reference solution. */
protected Classifier[] loadClassifierFromArff(String arffWithTrainingData) {
    weka.classifiers.trees.REPTree tree = new weka.classifiers.trees.REPTree();
    tree.setMaxDepth(3);/*from   w  w w.j a v a 2  s. c  o m*/
    tree.setNoPruning(true);// since we only use the tree as a classifier (as a conservative extension of what is currently done) and do not actually look at it, elimination of pruning is not a problem. 
    // As part of learning, we also prune some of the nodes where the ratio of correctly-classified pairs to those incorrectly classified is comparable.
    // The significant advantage of not pruning is that the result is no longer sensitive to the order of elements in the tree and hence does not depend on the order in which elements have been obtained by concurrent threads.
    weka.classifiers.trees.J48 tree48 = new weka.classifiers.trees.J48();
    tree48.setUnpruned(true);// since we only use the tree as a classifier (as a conservative extension of what is currently done) and do not actually look at it, elimination of pruning is not a problem. 
    // As part of learning, we also prune some of the nodes where the ratio of correctly-classified pairs to those incorrectly classified is comparable.
    // The significant advantage of not pruning is that the result is no longer sensitive to the order of elements in the tree and hence does not depend on the order in which elements have been obtained by concurrent threads.
    weka.classifiers.lazy.IBk ibk = new weka.classifiers.lazy.IBk(1);
    weka.classifiers.lazy.IB1 ib1 = new weka.classifiers.lazy.IB1();
    weka.classifiers.functions.MultilayerPerceptron perceptron = new weka.classifiers.functions.MultilayerPerceptron();
    Classifier[] outcome = new Classifier[] { ib1 };//tree};//,tree48,ibk};//,perceptron};
    for (Classifier c : outcome)
        trainClassifierFromArff(c, arffWithTrainingData);
    return outcome;
}