Example usage for weka.classifiers.evaluation EvaluationUtils getTestPredictions

List of usage examples for weka.classifiers.evaluation EvaluationUtils getTestPredictions

Introduction

In this page you can find the example usage for weka.classifiers.evaluation EvaluationUtils getTestPredictions.

Prototype

public ArrayList<Prediction> getTestPredictions(Classifier classifier, Instances test) throws Exception 

Source Link

Document

Generate a bunch of predictions ready for processing, by performing a evaluation on a test set assuming the classifier is already trained.

Usage

From source file:trainableSegmentation.Weka_Segmentation.java

License:GNU General Public License

/**
 * Display the threshold curve window (for precision/recall, ROC, etc.).
 *
 * @param data input instances/* www  .j  av a2 s . c o  m*/
 * @param classifier classifier to evaluate
 */
public static void displayGraphs(Instances data, AbstractClassifier classifier) {
    ThresholdCurve tc = new ThresholdCurve();

    FastVector predictions = null;
    try {
        final EvaluationUtils eu = new EvaluationUtils();
        predictions = eu.getTestPredictions(classifier, data);
    } catch (Exception e) {
        IJ.log("Error while evaluating data!");
        e.printStackTrace();
        return;
    }

    Instances result = tc.getCurve(predictions);
    ThresholdVisualizePanel vmc = new ThresholdVisualizePanel();
    vmc.setName(result.relationName() + " (display only)");
    PlotData2D tempd = new PlotData2D(result);
    tempd.setPlotName(result.relationName());
    tempd.addInstanceNumberAttribute();
    try {
        vmc.addPlot(tempd);
    } catch (Exception e) {
        IJ.log("Error while adding plot to visualization panel!");
        e.printStackTrace();
        return;
    }
    String plotName = vmc.getName();
    JFrame jf = new JFrame("Weka Classifier Visualize: " + plotName);
    jf.setSize(500, 400);
    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(vmc, BorderLayout.CENTER);
    jf.setVisible(true);
}