Example usage for weka.classifiers Evaluation sizeOfPredictedRegions

List of usage examples for weka.classifiers Evaluation sizeOfPredictedRegions

Introduction

In this page you can find the example usage for weka.classifiers Evaluation sizeOfPredictedRegions.

Prototype

public final double sizeOfPredictedRegions() 

Source Link

Document

Gets the average size of the predicted regions, relative to the range of the target in the training data, at the confidence level specified when evaluation was performed.

Usage

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

License:Open Source License

/**
 * {@inheritDoc}/*  ww  w.  j  a v a2s. co  m*/
 */
@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:lu.lippmann.cdb.dt.ModelTreeFactory.java

License:Open Source License

/**
 * Main method.//from w  w  w . j  a  v a  2  s  .co  m
 * @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();
    }
}

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

License:Open Source License

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

        final REPTree rt = new REPTree();
        rt.setMaxDepth(3);
        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));

        /*final String f2="./samples/csv/salary.csv";
        final Instances dataSet2=WekaDataAccessUtil.loadInstancesFromARFFOrCSVFile(new File(f2));
                
        final J48 j48=new J48();
        j48.buildClassifier(dataSet2);
        System.out.println(j48.graph());
        final GraphWithOperations gwo2=GraphUtil.buildGraphWithOperationsFromWekaString(j48.graph(),false);
        System.out.println(gwo2);*/

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

From source file:net.sf.jclal.evaluation.measure.SingleLabelEvaluation.java

License:Open Source License

/**
 *
 * @param evaluation The evaluation//from  ww w . jav  a 2 s  . c om
 */
public void setEvaluation(Evaluation evaluation) {

    try {
        this.evaluation = evaluation;
        StringBuilder st = new StringBuilder();

        st.append("Iteration: ").append(getIteration()).append("\n");
        st.append("Labeled set size: ").append(getLabeledSetSize()).append("\n");
        st.append("Unlabelled set size: ").append(getUnlabeledSetSize()).append("\n");
        st.append("\t\n");

        st.append("Correctly Classified Instances: ").append(evaluation.pctCorrect()).append("\n");
        st.append("Incorrectly Classified Instances: ").append(evaluation.pctIncorrect()).append("\n");
        st.append("Kappa statistic: ").append(evaluation.kappa()).append("\n");
        st.append("Mean absolute error: ").append(evaluation.meanAbsoluteError()).append("\n");
        st.append("Root mean squared error: ").append(evaluation.rootMeanSquaredError()).append("\n");

        st.append("Relative absolute error: ").append(evaluation.relativeAbsoluteError()).append("\n");
        st.append("Root relative squared error: ").append(evaluation.rootRelativeSquaredError()).append("\n");
        st.append("Coverage of cases: ").append(evaluation.coverageOfTestCasesByPredictedRegions())
                .append("\n");
        st.append("Mean region size: ").append(evaluation.sizeOfPredictedRegions()).append("\n");

        st.append("Weighted Precision: ").append(evaluation.weightedPrecision()).append("\n");
        st.append("Weighted Recall: ").append(evaluation.weightedRecall()).append("\n");
        st.append("Weighted FMeasure: ").append(evaluation.weightedFMeasure()).append("\n");
        st.append("Weighted TruePositiveRate: ").append(evaluation.weightedTruePositiveRate()).append("\n");
        st.append("Weighted FalsePositiveRate: ").append(evaluation.weightedFalsePositiveRate()).append("\n");
        st.append("Weighted MatthewsCorrelation: ").append(evaluation.weightedMatthewsCorrelation())
                .append("\n");
        st.append("Weighted AreaUnderROC: ").append(evaluation.weightedAreaUnderROC()).append("\n");
        st.append("Weighted AreaUnderPRC: ").append(evaluation.weightedAreaUnderPRC()).append("\n");

        st.append("\t\t\n");

        loadMetrics(st.toString());

    } catch (Exception e) {
        Logger.getLogger(SingleLabelEvaluation.class.getName()).log(Level.SEVERE, null, e);
    }
}