Example usage for weka.gui.visualize ThresholdVisualizePanel setROCString

List of usage examples for weka.gui.visualize ThresholdVisualizePanel setROCString

Introduction

In this page you can find the example usage for weka.gui.visualize ThresholdVisualizePanel setROCString.

Prototype

public void setROCString(String str) 

Source Link

Document

Set the string with ROC area

Usage

From source file:adams.gui.menu.ROC.java

License:Open Source License

/**
 * Launches the functionality of the menu item.
 *///from   w w  w .ja v a  2s.co  m
@Override
public void launch() {
    File file;
    if (m_Parameters.length == 0) {
        // choose file
        int retVal = m_FileChooser.showOpenDialog(null);
        if (retVal != JFileChooser.APPROVE_OPTION)
            return;
        file = m_FileChooser.getSelectedFile();
    } else {
        file = new PlaceholderFile(m_Parameters[0]).getAbsoluteFile();
        m_FileChooser.setSelectedFile(file);
    }

    // create plot
    Instances result;
    try {
        result = m_FileChooser.getLoader().getDataSet();
    } catch (Exception e) {
        GUIHelper.showErrorMessage(getOwner(),
                "Error loading file '" + file + "':\n" + adams.core.Utils.throwableToString(e));
        return;
    }
    result.setClassIndex(result.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " + Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")");
    vmc.setName(result.relationName());
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    // specify which points are connected
    boolean[] cp = new boolean[result.numInstances()];
    for (int n = 1; n < cp.length; n++)
        cp[n] = true;
    try {
        tempd.setConnectPoints(cp);
        vmc.addPlot(tempd);
    } catch (Exception e) {
        GUIHelper.showErrorMessage(getOwner(), "Error adding plot:\n" + adams.core.Utils.throwableToString(e));
        return;
    }

    ChildFrame frame = createChildFrame(vmc, GUIHelper.getDefaultDialogDimension());
    frame.setTitle(frame.getTitle() + " - " + file);
}

From source file:com.sliit.views.DataVisualizerPanel.java

void getRocCurve() {
    try {//from ww w.  ja v a  2 s. c  o m
        Instances data;
        data = new Instances(new BufferedReader(new FileReader(datasetPathText.getText())));
        data.setClassIndex(data.numAttributes() - 1);

        // train classifier
        Classifier cl = new NaiveBayes();
        Evaluation eval = new Evaluation(data);
        eval.crossValidateModel(cl, data, 10, new Random(1));

        // generate curve
        ThresholdCurve tc = new ThresholdCurve();
        int classIndex = 0;
        Instances result = tc.getCurve(eval.predictions(), classIndex);

        // plot curve
        ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
        vmc.setROCString("(Area under ROC = " + Utils.doubleToString(tc.getROCArea(result), 4) + ")");
        vmc.setName(result.relationName());
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        // specify which points are connected
        boolean[] cp = new boolean[result.numInstances()];
        for (int n = 1; n < cp.length; n++) {
            cp[n] = true;
        }
        tempd.setConnectPoints(cp);
        // add plot
        vmc.addPlot(tempd);

        // display curve
        String plotName = vmc.getName();
        final javax.swing.JFrame jf = new javax.swing.JFrame("Weka Classifier Visualize: " + plotName);
        jf.setSize(500, 400);
        jf.getContentPane().setLayout(new BorderLayout());
        jf.getContentPane().add(vmc, BorderLayout.CENTER);
        jf.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent e) {
                jf.dispose();
            }
        });
        jf.setVisible(true);
    } catch (IOException ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.sliit.views.KNNView.java

void getRocCurve() {
    try {//w  w  w  .  j  a v  a2  s  .c  o  m
        Instances data;
        data = new Instances(new BufferedReader(new java.io.FileReader(PredictorPanel.modalText.getText())));
        data.setClassIndex(data.numAttributes() - 1);

        // train classifier
        Classifier cl = new NaiveBayes();
        Evaluation eval = new Evaluation(data);
        eval.crossValidateModel(cl, data, 10, new Random(1));

        // generate curve
        ThresholdCurve tc = new ThresholdCurve();
        int classIndex = 0;
        Instances result = tc.getCurve(eval.predictions(), classIndex);

        // plot curve
        ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
        vmc.setROCString("(Area under ROC = " + Utils.doubleToString(tc.getROCArea(result), 4) + ")");
        vmc.setName(result.relationName());
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        // specify which points are connected
        boolean[] cp = new boolean[result.numInstances()];
        for (int n = 1; n < cp.length; n++) {
            cp[n] = true;
        }
        tempd.setConnectPoints(cp);
        // add plot
        vmc.addPlot(tempd);

        rocPanel.removeAll();
        rocPanel.add(vmc, "vmc", 0);
        rocPanel.revalidate();

    } catch (IOException ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.sliit.views.SVMView.java

/**
 * draw ROC curve/*from w w w.  j  av  a  2 s  .c  om*/
 */
void getRocCurve() {
    try {
        Instances data;
        data = new Instances(new BufferedReader(new FileReader(PredictorPanel.modalText.getText())));
        data.setClassIndex(data.numAttributes() - 1);

        //train classifier
        Classifier cl = new NaiveBayes();
        Evaluation eval = new Evaluation(data);
        eval.crossValidateModel(cl, data, 10, new Random(1));

        // generate curve
        ThresholdCurve tc = new ThresholdCurve();
        int classIndex = 0;
        Instances result = tc.getCurve(eval.predictions(), classIndex);

        // plot curve
        ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
        vmc.setROCString("(Area under ROC = " + Utils.doubleToString(tc.getROCArea(result), 4) + ")");
        vmc.setName(result.relationName());
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        // specify which points are connected
        boolean[] cp = new boolean[result.numInstances()];
        for (int n = 1; n < cp.length; n++) {
            cp[n] = true;
        }
        tempd.setConnectPoints(cp);
        // add plot
        vmc.addPlot(tempd);

        //            rocPanel.removeAll();
        //            rocPanel.add(vmc, "vmc", 0);
        //            rocPanel.revalidate();
    } catch (IOException ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(DataVisualizerPanel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:meka.gui.explorer.classify.ShowPrecisionRecall.java

License:Open Source License

/**
 * Creates a panel displaying the ROC data.
 *
 * @param data          the threshold curve data
 * @param title         the title of the plot
 * @return              the panel/*from  www. j  ava2 s . com*/
 * @throws Exception    if plot generation fails
 */
protected ThresholdVisualizePanel createPanel(Instances data, String title) throws Exception {
    ThresholdVisualizePanel result = super.createPanel(data, title);
    result.setROCString("PRC area: " + Utils.doubleToString(ThresholdCurve.getPRCArea(data), 3));
    result.setUpComboBoxes(result.getInstances());
    setComboBoxIndices(data, result);
    return result;
}

From source file:meka.gui.explorer.classify.ShowROC.java

License:Open Source License

/**
 * Creates a panel displaying the ROC data.
 *
 * @param data          the threshold curve data
 * @param title         the title of the plot
 * @return              the panel/*from   ww w. j  av a 2 s. c o m*/
 * @throws Exception    if plot generation fails
 */
protected ThresholdVisualizePanel createPanel(Instances data, String title) throws Exception {
    ThresholdVisualizePanel result = super.createPanel(data, title);
    result.setROCString("AUC: " + Utils.doubleToString(ThresholdCurve.getROCArea(data), 3));
    result.setUpComboBoxes(result.getInstances());
    return result;
}

From source file:meka.gui.guichooser.PrecisionRecallCurve.java

License:Open Source License

/**
 * Called by the menu items action listener.
 *//*from   w  w  w . j  a v a 2  s . c  om*/
@Override
protected void launch() {
    m_FileChooser = GUIHelper.newConverterFileChooser();
    // choose file
    int retVal = m_FileChooser.showOpenDialog(null);
    if (retVal != JFileChooser.APPROVE_OPTION)
        return;
    File file = m_FileChooser.getSelectedFile();

    // create plot
    Instances data;
    try {
        data = m_FileChooser.getLoader().getDataSet();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error loading file '" + file + "':\n" + e, "Error",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }
    data.setClassIndex(data.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under PRC = " + Utils.doubleToString(ThresholdCurve.getPRCArea(data), 4) + ")");
    vmc.setName(data.relationName());
    PlotData2D tempd = new PlotData2D(data);
    tempd.setPlotName(data.relationName());
    tempd.m_displayAllPoints = true;
    // specify which points are connected
    boolean[] cp = new boolean[data.numInstances()];
    for (int n = 1; n < cp.length; n++)
        cp[n] = true;
    try {
        tempd.setConnectPoints(cp);
        vmc.addPlot(tempd);
        if (data.attribute(ThresholdCurve.RECALL_NAME) != null)
            vmc.setXIndex(data.attribute(ThresholdCurve.RECALL_NAME).index());
        if (data.attribute(ThresholdCurve.PRECISION_NAME) != null)
            vmc.setYIndex(data.attribute(ThresholdCurve.PRECISION_NAME).index());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error adding plot:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }

    MekaFrame frame = new MekaFrame();
    frame.setTitle(getName());
    frame.setDefaultCloseOperation(MekaFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(vmc);
    frame.setSize(800, 600);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:meka.gui.guichooser.ROC.java

License:Open Source License

/**
 * Called by the menu items action listener.
 *//*from   w  w w .  j a va 2 s .  c o m*/
@Override
protected void launch() {
    m_FileChooser = GUIHelper.newConverterFileChooser();
    // choose file
    int retVal = m_FileChooser.showOpenDialog(null);
    if (retVal != JFileChooser.APPROVE_OPTION)
        return;
    File file = m_FileChooser.getSelectedFile();

    // create plot
    Instances data;
    try {
        data = m_FileChooser.getLoader().getDataSet();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error loading file '" + file + "':\n" + e, "Error",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }
    data.setClassIndex(data.numAttributes() - 1);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setROCString("(Area under ROC = " + Utils.doubleToString(ThresholdCurve.getROCArea(data), 4) + ")");
    vmc.setName(data.relationName());
    PlotData2D tempd = new PlotData2D(data);
    tempd.setPlotName(data.relationName());
    tempd.m_displayAllPoints = true;
    // specify which points are connected
    boolean[] cp = new boolean[data.numInstances()];
    for (int n = 1; n < cp.length; n++)
        cp[n] = true;
    try {
        tempd.setConnectPoints(cp);
        vmc.addPlot(tempd);
        if (data.attribute(ThresholdCurve.FP_RATE_NAME) != null)
            vmc.setXIndex(data.attribute(ThresholdCurve.FP_RATE_NAME).index());
        if (data.attribute(ThresholdCurve.TP_RATE_NAME) != null)
            vmc.setYIndex(data.attribute(ThresholdCurve.TP_RATE_NAME).index());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Error adding plot:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return;
    }

    MekaFrame frame = new MekaFrame();
    frame.setTitle(getName());
    frame.setDefaultCloseOperation(MekaFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(vmc);
    frame.setSize(800, 600);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:miRdup.WekaModule.java

License:Open Source License

public static void rocCurve(Evaluation eval) {
    try {/* w w w.jav  a 2  s  .  co  m*/
        // generate curve
        ThresholdCurve tc = new ThresholdCurve();
        int classIndex = 0;
        Instances result = tc.getCurve(eval.predictions(), classIndex);
        result.toString();
        // plot curve
        ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
        vmc.setROCString("(Area under ROC = " + Utils.doubleToString(tc.getROCArea(result), 4) + ")");
        vmc.setName(result.relationName());
        PlotData2D tempd = new PlotData2D(result);
        tempd.setPlotName(result.relationName());
        tempd.addInstanceNumberAttribute();
        // specify which points are connected
        boolean[] cp = new boolean[result.numInstances()];
        for (int n = 1; n < cp.length; n++) {
            cp[n] = true;
        }
        tempd.setConnectPoints(cp);
        // add plot
        vmc.addPlot(tempd);

        //
        result.toString();

        // display curve
        String plotName = vmc.getName();
        final javax.swing.JFrame jf = new javax.swing.JFrame("Weka Classifier Visualize: " + plotName);
        jf.setSize(500, 400);
        jf.getContentPane().setLayout(new BorderLayout());
        jf.getContentPane().add(vmc, BorderLayout.CENTER);
        jf.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent e) {
                jf.dispose();
            }
        });

        jf.setVisible(true);
        System.out.println("");
    } catch (Exception e) {
        e.printStackTrace();
    }

}