List of usage examples for weka.classifiers.evaluation ThresholdCurve getCurve
public Instances getCurve(ArrayList<Prediction> predictions)
From source file:TextClassifierUI.java
private void setVMC(FastVector predictions, ThresholdVisualizePanel vmc, boolean masterPlot) { try {/* ww w.jav a2s . c o m*/ ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(predictions); // method visualize 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 if (masterPlot) { vmc.setMasterPlot(tempd); } else { vmc.addPlot(tempd); } } catch (Exception ex) { System.err.println("Failed to set VMC"); ex.printStackTrace(); } }
From source file:meka.core.Metrics.java
License:Open Source License
/** Calculate AUPRC: Area Under the Precision-Recall curve. */ public static double P_macroAUPRC(int Y[][], double P[][]) { // works with missing int L = Y[0].length; double AUC[] = new double[L]; for (int j = 0; j < L; j++) { if (allMissing(Y[j])) { L--;//ww w . j a v a 2s. c o m continue; } ThresholdCurve curve = new ThresholdCurve(); Instances result = curve .getCurve(MLUtils.toWekaPredictions(MatrixUtils.getCol(Y, j), MatrixUtils.getCol(P, j))); AUC[j] = ThresholdCurve.getPRCArea(result); } return Utils.mean(AUC); }
From source file:meka.core.Metrics.java
License:Open Source License
/** Calculate AUROC: Area Under the ROC curve. */ public static double P_macroAUROC(int Y[][], double P[][]) { // works with missing int L = Y[0].length; double AUC[] = new double[L]; for (int j = 0; j < L; j++) { if (allMissing(Y[j])) { L--;/*from w w w. jav a2s .co m*/ continue; } ThresholdCurve curve = new ThresholdCurve(); Instances result = curve .getCurve(MLUtils.toWekaPredictions(MatrixUtils.getCol(Y, j), MatrixUtils.getCol(P, j))); AUC[j] = ThresholdCurve.getROCArea(result); } return Utils.mean(AUC); }
From source file:meka.core.Metrics.java
License:Open Source License
/** Get Data for Plotting PR and ROC curves. */ public static Instances curveDataMicroAveraged(int Y[][], double P[][]) { //works with missing int y[] = MatrixUtils.flatten(Y); double p[] = MatrixUtils.flatten(P); double[][] aligned = align(y, p); y = toIntArray(aligned[0]);//from w w w.j ava 2 s. co m p = aligned[1]; ThresholdCurve curve = new ThresholdCurve(); return curve.getCurve(MLUtils.toWekaPredictions(y, p)); }
From source file:meka.core.Metrics.java
License:Open Source License
/** Get Data for Plotting PR and ROC curves. */ public static Instances curveData(int y[], double p[]) { // works with missing double[][] aligned = align(y, p); y = toIntArray(aligned[0]);/*from ww w .j a v a 2 s. co m*/ p = aligned[1]; ThresholdCurve curve = new ThresholdCurve(); return curve.getCurve(MLUtils.toWekaPredictions(y, p)); }
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//from w w w .j a v a2 s .com * @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); }