@Test public void testAuc() { Auc auc = new Auc(); Random gen = RandomUtils.getRandom(); auc.setProbabilityScore(false); for (int i=0; i<100000; i++) { auc.add(0, gen.nextGaussian()); auc.add(1, gen.nextGaussian() + 1); } assertEquals(0.76, auc.auc(), 0.01); }
public static void main(String[] args) throws IOException { String inputFile = args[1]; Auc x1 = new Auc(); OnlineAuc x2 = new GlobalOnlineAuc(); BufferedReader in = new BufferedReader(new FileReader(inputFile)); int lineCount = 0; String line = in.readLine(); while (line != null) { lineCount++; String[] pieces = line.split(","); double score = Double.parseDouble(pieces[0]); int target = Integer.parseInt(pieces[1]); x1.add(target, score); x2.addSample(target, score); if (lineCount%500 == 0) { System.out.printf("%10d\t%10.3f\t%10d\t%.3f\n", lineCount, score, target, x2.auc()); } line = in.readLine(); } System.out.printf("%d lines read\n", lineCount); System.out.printf("%10.2f = batch estimate\n", x1.auc()); System.out.printf("%10.2f = on-line estimate\n", x2.auc()); } }
@Test public void testEntropy() { Auc auc = new Auc(); Random gen = RandomUtils.getRandom(); Normal n0 = new Normal(-1, 1, gen); Normal n1 = new Normal(1, 1, gen); for (int i=0; i<100000; i++) { double score = n0.nextDouble(); double p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score)); auc.add(0, p); score = n1.nextDouble(); p = n1.pdf(score) / (n0.pdf(score) + n1.pdf(score)); auc.add(1, p); } Matrix m = auc.entropy(); assertEquals(-0.35, m.get(0, 0), 0.02); assertEquals(-2.36, m.get(0, 1), 0.02); assertEquals(-2.36, m.get(1, 0), 0.02); assertEquals(-0.35, m.get(1, 1), 0.02); } }
if (isProbabilityScore()) { double limited = Math.max(1.0e-20, Math.min(score, 1 - 1.0e-20)); double v0 = entropy.get(trueValue, 0);
@Test public void testTies() { Auc auc = new Auc(); Random gen = RandomUtils.getRandom(); auc.setProbabilityScore(false); for (int i=0; i<100000; i++) { auc.add(0, gen.nextGaussian()); auc.add(1, gen.nextGaussian() + 1); } // ties outside the normal range could cause index out of range auc.add(0, 5.0); auc.add(0, 5.0); auc.add(0, 5.0); auc.add(0, 5.0); auc.add(1, 5.0); auc.add(1, 5.0); auc.add(1, 5.0); assertEquals(0.76, auc.auc(), 0.05); }
if (isProbabilityScore()) { double limited = Math.max(1.0e-20, Math.min(score, 1 - 1.0e-20)); double v0 = entropy.get(trueValue, 0);
if (isProbabilityScore()) { double limited = Math.max(1.0e-20, Math.min(score, 1 - 1.0e-20)); double v0 = entropy.get(trueValue, 0);