public static void main(String[] args) { ClassifierOutput output = new ClassifierOutput(); /*output.scoreLabelPairs.add(new ScoreLabelPair(5, true)); output.scoreLabelPairs.add(new ScoreLabelPair(0, true)); output.scoreLabelPairs.add(new ScoreLabelPair(9, true)); output.scoreLabelPairs.add(new ScoreLabelPair(8, true)); output.scoreLabelPairs.add(new ScoreLabelPair(5, true)); output.scoreLabelPairs.add(new ScoreLabelPair(0, false)); output.scoreLabelPairs.add(new ScoreLabelPair(0, false)); output.scoreLabelPairs.add(new ScoreLabelPair(0, false)); output.scoreLabelPairs.add(new ScoreLabelPair(5, false)); */ output.scoreLabelPairs.add(new ScoreLabelPair(5, false)); output.scoreLabelPairs.add(new ScoreLabelPair(4, true)); output.scoreLabelPairs.add(new ScoreLabelPair(3, true)); output.scoreLabelPairs.add(new ScoreLabelPair(2, true)); output.scoreLabelPairs.add(new ScoreLabelPair(1, true)); output.scoreLabelPairs.add(new ScoreLabelPair(ScoreLabelPair.LOW_NUMBER, false)); output.scoreLabelPairs.add(new ScoreLabelPair(ScoreLabelPair.LOW_NUMBER, false)); output.scoreLabelPairs.add(new ScoreLabelPair(ScoreLabelPair.LOW_NUMBER, false)); output.scoreLabelPairs.add(new ScoreLabelPair(ScoreLabelPair.LOW_NUMBER, true)); output.scoreLabelPairs.add(new ScoreLabelPair(ScoreLabelPair.LOW_NUMBER, true)); System.out.println(ClassifierEvaluator.areaUnderCurve(output)); System.out.println(ClassifierEvaluator.areaUnderCurveConfidenceInterval(output).pointEstimate); System.out.println(ClassifierEvaluator.areaUnderCurveConfidenceInterval(output).lowerBound); System.out.println(ClassifierEvaluator.areaUnderCurveConfidenceInterval(output).upperBound); System.out.println(ClassifierEvaluator.bpref(output)); }
public static void createROC(ClassifierOutput classifierOutput, String filename) { WriteTextFile out = null; if (outputROCcsv) { out = new WriteTextFile(filename.replace(".gif", ".csv")); out.writeln("FPR,TPR"); } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = (Graphics2D) img.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, width, height); renderAxes(g2d, 0.2f, 1f); // renderDiagonal(g2d); renderROC(g2d, classifierOutput, out); if (includeAuCinROC) { double auc = ClassifierEvaluator.areaUnderCurveConfidenceInterval(classifierOutput).pointEstimate; g2d.setColor(Color.black); g2d.setFont(new Font("Arial", Font.PLAIN, 50)); FontMetrics metrics = g2d.getFontMetrics(); String text = "AUC = " + StringUtilities.formatNumber("0.00", auc); int textWidth = metrics.stringWidth(text); int textHeight = metrics.getHeight(); g2d.drawString( text, Math.round(width - textWidth - borderWidth), Math.round(height - textHeight) + 7); } try { ImageIO.write(img, "GIF", new File(filename)); } catch (IOException e) { e.printStackTrace(); } if (out != null) out.close(); }