Package org.apache.mahout.math.stats

Examples of org.apache.mahout.math.stats.OnlineAuc


  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())
    }
View Full Code Here


  }

  @Test
  public void onlineAucRoundtrip() {
    RandomUtils.useTestSeed();
    OnlineAuc auc1 = new GlobalOnlineAuc();
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < 10000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);
    }
    assertEquals(0.76, auc1.auc(), 0.01);

    Gson gson = ModelSerializer.gson();
    String s = gson.toJson(auc1);

    OnlineAuc auc2 = gson.fromJson(s, GlobalOnlineAuc.class);

    assertEquals(auc1.auc(), auc2.auc(), 0);

    for (int i = 0; i < 1000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);

      auc2.addSample(0, gen.nextGaussian());
      auc2.addSample(1, gen.nextGaussian() + 1);
    }

    assertEquals(auc1.auc(), auc2.auc(), 0.01);

    Foo x = new Foo();
    x.foo = auc1;
    x.pig = 3.13;
    x.dog = 42;
View Full Code Here

  }

  @Test
  public void onlineAucRoundtrip() throws IOException {
    RandomUtils.useTestSeed();
    OnlineAuc auc1 = new GlobalOnlineAuc();
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < 10000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);
    }
    assertEquals(0.76, auc1.auc(), 0.01);

    OnlineAuc auc3 = roundTrip(auc1, OnlineAuc.class);

    assertEquals(auc1.auc(), auc3.auc(), 0);

    for (int i = 0; i < 1000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);

      auc3.addSample(0, gen.nextGaussian());
      auc3.addSample(1, gen.nextGaussian() + 1);
    }

    assertEquals(auc1.auc(), auc3.auc(), 0.01);
  }
View Full Code Here

  }

  @Test
  public void onlineAucRoundtrip() throws IOException {
    RandomUtils.useTestSeed();
    OnlineAuc auc1 = new GlobalOnlineAuc();
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < 10000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);
    }
    assertEquals(0.76, auc1.auc(), 0.01);

    OnlineAuc auc3 = roundTrip(auc1, OnlineAuc.class);

    assertEquals(auc1.auc(), auc3.auc(), 0);

    for (int i = 0; i < 1000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);

      auc3.addSample(0, gen.nextGaussian());
      auc3.addSample(1, gen.nextGaussian() + 1);
    }

    assertEquals(auc1.auc(), auc3.auc(), 0.01);
  }
View Full Code Here

  }

  @Test
  public void onlineAucRoundtrip() throws IOException {
    RandomUtils.useTestSeed();
    OnlineAuc auc1 = new GlobalOnlineAuc();
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < 10000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);
    }
    assertEquals(0.76, auc1.auc(), 0.01);

    OnlineAuc auc3 = roundTrip(auc1, OnlineAuc.class);

    assertEquals(auc1.auc(), auc3.auc(), 0);

    for (int i = 0; i < 1000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);

      auc3.addSample(0, gen.nextGaussian());
      auc3.addSample(1, gen.nextGaussian() + 1);
    }

    assertEquals(auc1.auc(), auc3.auc(), 0.01);
  }
View Full Code Here

  }

  @Test
  public void onlineAucRoundtrip() throws IOException {
    RandomUtils.useTestSeed();
    OnlineAuc auc1 = new GlobalOnlineAuc();
    Random gen = RandomUtils.getRandom();
    for (int i = 0; i < 10000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);
    }
    assertEquals(0.76, auc1.auc(), 0.01);

    OnlineAuc auc3 = roundTrip(auc1, OnlineAuc.class);

    assertEquals(auc1.auc(), auc3.auc(), 0);

    for (int i = 0; i < 1000; i++) {
      auc1.addSample(0, gen.nextGaussian());
      auc1.addSample(1, gen.nextGaussian() + 1);

      auc3.addSample(0, gen.nextGaussian());
      auc3.addSample(1, gen.nextGaussian() + 1);
    }

    assertEquals(auc1.auc(), auc3.auc(), 0.01);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.stats.OnlineAuc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.