List of usage examples for weka.classifiers.evaluation ThresholdCurve getROCArea
public static double getROCArea(Instances tcurve)
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// ww w .j av a2 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.ROC.java
License:Open Source License
/** * Called by the menu items action listener. *///ww 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 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 {//from w w w. j a v a 2s . 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(); } }
From source file:mlflex.WekaInMemoryLearner.java
License:Open Source License
/** This method calculates the area under the curve for a set of predictions and is designed to support classification of more than two classes. This code was derived from Weka's source code. * * @param predictions Predictions that have been made * @return Area under the curve, weighted by the proportion of instances for each class * @throws Exception/* www . j a va 2s. com*/ */ // public static double CalculateWeightedAreaUnderRoc(Predictions predictions) throws Exception { ArrayList<String> uniqueActualClasses = predictions.GetUniqueActualClasses(); if (uniqueActualClasses.size() == 0) return Double.NaN; if (predictions.Size() == 1) { if (predictions.Get(0).WasCorrect()) return 1.0; return 0.5; } if (uniqueActualClasses.size() == 1) return 0.5; ArrayList<String> dependentVariableClasses = Utilities.ProcessorVault.DependentVariableDataProcessor .GetUniqueDependentVariableValues(); FastVector predictionVector = new FastVector(); for (Prediction prediction : predictions) predictionVector.addElement( new NominalPrediction(dependentVariableClasses.indexOf(prediction.DependentVariableValue), Lists.ConvertToDoubleArray(prediction.ClassProbabilities))); double aucTotal = 0; for (int i = 0; i < dependentVariableClasses.size(); i++) { String dependentVariableClass = dependentVariableClasses.get(i); Instances result = new ThresholdCurve().getCurve(predictionVector, i); double auc = ThresholdCurve.getROCArea(result); if (!Instance.isMissingValue(auc)) aucTotal += (auc * new PredictionResults(predictions) .GetNumActualsWithDependentVariableClass(dependentVariableClass)); } return aucTotal / predictions.Size(); }
From source file:mulan.evaluation.measure.MacroAUC.java
License:Open Source License
public double getValue() { double[] labelAUC = new double[numOfLabels]; for (int i = 0; i < numOfLabels; i++) { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(m_Predictions[i], 1); labelAUC[i] = ThresholdCurve.getROCArea(result); }/* ww w . j ava 2 s .com*/ return Utils.mean(labelAUC); }
From source file:mulan.evaluation.measure.MicroAUC.java
License:Open Source License
public double getValue() { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(all_Predictions, 1); return ThresholdCurve.getROCArea(result); }