List of usage examples for weka.classifiers.evaluation ThresholdCurve getPRCArea
public static double getPRCArea(Instances tcurve)
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--;//from w w 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.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 ww w. j av a2s .co m * @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.guichooser.PrecisionRecallCurve.java
License:Open Source License
/** * Called by the menu items action listener. *//*from w w w . j av a 2s. 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); }