Example usage for weka.classifiers.evaluation CostCurve getCurve

List of usage examples for weka.classifiers.evaluation CostCurve getCurve

Introduction

In this page you can find the example usage for weka.classifiers.evaluation CostCurve getCurve.

Prototype

public Instances getCurve(ArrayList<Prediction> predictions, int classIndex) 

Source Link

Document

Calculates the performance stats for the desired class and return results as a set of Instances.

Usage

From source file:adams.data.conversion.WekaEvaluationToCostCurve.java

License:Open Source License

/**
 * Performs the actual conversion.//  ww  w . j  a v  a  2 s. com
 *
 * @return      the converted data
 * @throws Exception   if something goes wrong with the conversion
 */
@Override
protected Object doConvert() throws Exception {
    Evaluation eval;
    CostCurve curve;
    Instances cost;

    eval = (Evaluation) m_Input;
    m_ClassLabelIndex.setMax(eval.getHeader().classAttribute().numValues());
    curve = new CostCurve();
    cost = curve.getCurve(eval.predictions(), m_ClassLabelIndex.getIntIndex());

    return cost;
}

From source file:adams.flow.sink.WekaCostCurve.java

License:Open Source License

/**
 * Plots the token (the panel and dialog have already been created at
 * this stage)./* ww w  . j  a  v a 2 s.  c o  m*/
 *
 * @param token   the token to display
 */
@Override
protected void display(Token token) {
    weka.classifiers.evaluation.CostCurve curve;
    Evaluation eval;
    PlotData2D plot;
    boolean[] connectPoints;
    int cp;
    Instances data;
    int[] indices;

    try {
        if (token.getPayload() instanceof WekaEvaluationContainer)
            eval = (Evaluation) ((WekaEvaluationContainer) token.getPayload())
                    .getValue(WekaEvaluationContainer.VALUE_EVALUATION);
        else
            eval = (Evaluation) token.getPayload();
        if (eval.predictions() == null) {
            getLogger().severe("No predictions available from Evaluation object!");
            return;
        }
        m_ClassLabelRange.setData(eval.getHeader().classAttribute());
        indices = m_ClassLabelRange.getIntIndices();
        for (int index : indices) {
            curve = new weka.classifiers.evaluation.CostCurve();
            data = curve.getCurve(eval.predictions(), index);
            plot = new PlotData2D(data);
            plot.setPlotName(eval.getHeader().classAttribute().value(index));
            plot.m_displayAllPoints = true;
            connectPoints = new boolean[data.numInstances()];
            for (cp = 1; cp < connectPoints.length; cp++)
                connectPoints[cp] = true;
            plot.setConnectPoints(connectPoints);
            m_VisualizePanel.addPlot(plot);
        }
    } catch (Exception e) {
        handleException("Failed to display token: " + token, e);
    }
}

From source file:adams.flow.sink.WekaCostCurve.java

License:Open Source License

/**
 * Creates a new panel for the token.//from www.j  a v  a 2 s  .c  om
 *
 * @param token   the token to display in a new panel, can be null
 * @return      the generated panel
 */
public AbstractDisplayPanel createDisplayPanel(Token token) {
    AbstractDisplayPanel result;
    String name;

    if (token != null)
        name = "Cost curve (" + getEvaluation(token).getHeader().relationName() + ")";
    else
        name = "Cost curve";

    result = new AbstractComponentDisplayPanel(name) {
        private static final long serialVersionUID = -3513994354297811163L;
        protected VisualizePanel m_VisualizePanel;

        @Override
        protected void initGUI() {
            super.initGUI();
            setLayout(new BorderLayout());
            m_VisualizePanel = new VisualizePanel();
            add(m_VisualizePanel, BorderLayout.CENTER);
        }

        @Override
        public void display(Token token) {
            try {
                Evaluation eval = getEvaluation(token);
                m_ClassLabelRange.setMax(eval.getHeader().classAttribute().numValues());
                int[] indices = m_ClassLabelRange.getIntIndices();
                for (int index : indices) {
                    weka.classifiers.evaluation.CostCurve curve = new weka.classifiers.evaluation.CostCurve();
                    Instances data = curve.getCurve(eval.predictions(), index);
                    PlotData2D plot = new PlotData2D(data);
                    plot.setPlotName(eval.getHeader().classAttribute().value(index));
                    plot.m_displayAllPoints = true;
                    boolean[] connectPoints = new boolean[data.numInstances()];
                    for (int cp = 1; cp < connectPoints.length; cp++)
                        connectPoints[cp] = true;
                    plot.setConnectPoints(connectPoints);
                    m_VisualizePanel.addPlot(plot);
                }
            } catch (Exception e) {
                getLogger().log(Level.SEVERE, "Failed to display token: " + token, e);
            }
        }

        @Override
        public JComponent supplyComponent() {
            return m_VisualizePanel;
        }

        @Override
        public void clearPanel() {
            m_VisualizePanel.removeAllPlots();
        }

        public void cleanUp() {
            m_VisualizePanel.removeAllPlots();
        }
    };

    if (token != null)
        result.display(token);

    return result;
}