/** 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]); p = aligned[1]; ThresholdCurve curve = new ThresholdCurve(); return curve.getCurve(MLUtils.toWekaPredictions(y,p)); }
public double getValue() { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(all_Predictions, 1); return ThresholdCurve.getROCArea(result); } }
continue; ThresholdCurve curve = new ThresholdCurve(); curve.getCurve(MLUtils.toWekaPredictions(toIntArray(aligned[0]), aligned[1])); if (roc) { AUC[j] = ThresholdCurve.getROCArea(result); } else { AUC[j] = ThresholdCurve.getPRCArea(result);
/** * Returns the area under precision-recall curve (AUPRC) for those predictions * that have been collected in the evaluateClassifier(Classifier, Instances) * method. Returns Utils.missingValue() if the area is not available. * * @param classIndex the index of the class to consider as "positive" * @return the area under the precision-recall curve or not a number */ public double areaUnderPRC(int classIndex) { // Check if any predictions have been collected if (m_Predictions == null) { return Utils.missingValue(); } else { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(m_Predictions, classIndex); return ThresholdCurve.getPRCArea(result); } }
System.out.println(ThresholdCurve.getNPointPrecision(inst, 11)); } else if (3 != 1 + 1) { // true inst.setClassIndex(inst.numAttributes() - 1); ThresholdCurve tc = new ThresholdCurve(); EvaluationUtils eu = new EvaluationUtils(); Classifier classifier = new weka.classifiers.functions.Logistic(); Instances result = tc.getCurve(predictions); System.out.println(result);
ThresholdVisualizePanel vmc = new ThresholdVisualizePanel(); vmc.setROCString("(Area under ROC = " + Utils.doubleToString(ThresholdCurve.getROCArea(result), 4) + ")"); vmc.setName(result.relationName()); PlotData2D tempd = new PlotData2D(result);
double[] probs = getProbabilities(predictions, classIndex); Instances insts = makeHeader(); int[] sorted = Utils.sort(probs); TwoClassStats tc = new TwoClassStats(totPos, totNeg, 0, 0); tc.setTrueNegative(tc.getTrueNegative() + cumulativeNeg); threshold = probs[sorted[i]]; insts.add(makeInstance(tc, threshold)); cumulativePos = 0; cumulativeNeg = 0; tc = new TwoClassStats(0, 0, totNeg, totPos); threshold = probs[sorted[sorted.length - 1]] + 10e-6; insts.add(makeInstance(tc, threshold));
return null; return getCurve(predictions, ((NominalPrediction) predictions.get(0)).distribution().length - 1);
/** * Creates a panel displaying the ROC data. * * @param data the threshold curve data * @param title the title of the plot * @return the panel * @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; } }
/** * Gets the index of the instance with the closest threshold value to the * desired target * * @param tcurve a set of instances that have been generated by this class * @param threshold the target threshold * @return the index of the instance that has threshold closest to the target, * or -1 if this could not be found (i.e. no data, or bad threshold * target) */ public static int getThresholdInstance(Instances tcurve, double threshold) { if (!RELATION_NAME.equals(tcurve.relationName()) || (tcurve.numInstances() == 0) || (threshold < 0) || (threshold > 1.0)) { return -1; } if (tcurve.numInstances() == 1) { return 0; } double[] tvals = tcurve.attributeToDoubleArray(tcurve.numAttributes() - 1); int[] sorted = Utils.sort(tvals); return binarySearch(sorted, tvals, threshold); }
/** * Returns the area under precision-recall curve (AUPRC) for those predictions * that have been collected in the evaluateClassifier(Classifier, Instances) * method. Returns Utils.missingValue() if the area is not available. * * @param classIndex the index of the class to consider as "positive" * @return the area under the precision-recall curve or not a number */ public double areaUnderPRC(int classIndex) { // Check if any predictions have been collected if (m_Predictions == null) { return Utils.missingValue(); } else { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(m_Predictions, classIndex); return ThresholdCurve.getPRCArea(result); } }
System.out.println(ThresholdCurve.getNPointPrecision(inst, 11)); } else if (3 != 1 + 1) { // true inst.setClassIndex(inst.numAttributes() - 1); ThresholdCurve tc = new ThresholdCurve(); EvaluationUtils eu = new EvaluationUtils(); Classifier classifier = new weka.classifiers.functions.Logistic(); Instances result = tc.getCurve(predictions); System.out.println(result);
/** * displays the previously saved instances * * @param insts the instances to display * @throws Exception if display is not possible */ @Override protected void openVisibleInstances(Instances insts) throws Exception { super.openVisibleInstances(insts); setROCString("(Area under ROC = " + Utils.doubleToString(ThresholdCurve.getROCArea(insts), 4) + ")"); setBorderText(); }
double[] probs = getProbabilities(predictions, classIndex); Instances insts = makeHeader(); int[] sorted = Utils.sort(probs); TwoClassStats tc = new TwoClassStats(totPos, totNeg, 0, 0); tc.setTrueNegative(tc.getTrueNegative() + cumulativeNeg); threshold = probs[sorted[i]]; insts.add(makeInstance(tc, threshold)); cumulativePos = 0; cumulativeNeg = 0; tc = new TwoClassStats(0, 0, totNeg, totPos); threshold = probs[sorted[sorted.length - 1]] + 10e-6; insts.add(makeInstance(tc, threshold));
return null; return getCurve(predictions, ((NominalPrediction) predictions.get(0)).distribution().length - 1);
/** * Creates a panel displaying the ROC data. * * @param data the threshold curve data * @param title the title of the plot * @return the panel * @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; } }
/** * Gets the index of the instance with the closest threshold value to the * desired target * * @param tcurve a set of instances that have been generated by this class * @param threshold the target threshold * @return the index of the instance that has threshold closest to the target, * or -1 if this could not be found (i.e. no data, or bad threshold * target) */ public static int getThresholdInstance(Instances tcurve, double threshold) { if (!RELATION_NAME.equals(tcurve.relationName()) || (tcurve.numInstances() == 0) || (threshold < 0) || (threshold > 1.0)) { return -1; } if (tcurve.numInstances() == 1) { return 0; } double[] tvals = tcurve.attributeToDoubleArray(tcurve.numAttributes() - 1); int[] sorted = Utils.sort(tvals); return binarySearch(sorted, tvals, threshold); }
/** 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]); p = aligned[1]; ThresholdCurve curve = new ThresholdCurve(); return curve.getCurve(MLUtils.toWekaPredictions(y,p)); }
/** * Returns the AUC for a particular label * * @param labelIndex the index of the label * @return the AUC for that label */ public double getValue(int labelIndex) { ThresholdCurve tc = new ThresholdCurve(); Instances result = tc.getCurve(m_Predictions[labelIndex], 1); return ThresholdCurve.getROCArea(result); }
continue; ThresholdCurve curve = new ThresholdCurve(); curve.getCurve(MLUtils.toWekaPredictions(toIntArray(aligned[0]), aligned[1])); if (roc) { AUC[j] = ThresholdCurve.getROCArea(result); } else { AUC[j] = ThresholdCurve.getPRCArea(result);