Esempio n. 1
0
 /** Test of learn method, of class FPGrowth. */
 @Test
 public void testLearn_PrintStream() {
   System.out.println("learn");
   FPGrowth fpgrowth = new FPGrowth(itemsets, 3);
   long n = fpgrowth.learn(System.out);
   assertEquals(8, n);
 }
Esempio n. 2
0
  /** Test of learn method, of class FPGrowth. */
  @Test
  public void testLearn_0args() {
    System.out.println("learn");
    FPGrowth fpgrowth = new FPGrowth(itemsets, 3);
    List<ItemSet> results = fpgrowth.learn();
    assertEquals(8, results.size());
    /*
    assertEquals(3, results.get(0).support);
    assertEquals(1, results.get(0).items.length);
    assertEquals(4, results.get(0).items[0]);

    assertEquals(5, results.get(1).support);
    assertEquals(1, results.get(1).items.length);
    assertEquals(1, results.get(1).items[0]);

    assertEquals(6, results.get(6).support);
    assertEquals(2, results.get(6).items.length);
    assertEquals(3, results.get(6).items[0]);
    assertEquals(2, results.get(6).items[1]);

    assertEquals(8, results.get(7).support);
    assertEquals(1, results.get(7).items.length);
    assertEquals(3, results.get(7).items[0]);
     */
  }
Esempio n. 3
0
  /** Test of learn method, of class FPGrowth. */
  @Test
  public void testKosarak() {
    System.out.println("kosarak");

    List<int[]> dataList = new ArrayList<int[]>(1000);

    try {
      InputStream stream = getClass().getResourceAsStream("/smile/data/transaction/kosarak.dat");
      BufferedReader input = new BufferedReader(new InputStreamReader(stream));

      String line;
      for (int nrow = 0; (line = input.readLine()) != null; nrow++) {
        if (line.trim().isEmpty()) {
          continue;
        }

        String[] s = line.split(" ");

        Set<Integer> items = new HashSet<Integer>();
        for (int i = 0; i < s.length; i++) {
          items.add(Integer.parseInt(s[i]));
        }

        int j = 0;
        int[] point = new int[items.size()];
        for (int i : items) {
          point[j++] = i;
        }
        dataList.add(point);
      }
    } catch (IOException ex) {
      System.err.println(ex);
    }

    int[][] data = dataList.toArray(new int[dataList.size()][]);

    int n = Math.max(data);
    System.out.format("%d transactions, %d items\n", data.length, n);

    long time = System.currentTimeMillis();
    FPGrowth fpgrowth = new FPGrowth(data, 1500);
    System.out.format(
        "Done building FP-tree: %.2f secs.\n", (System.currentTimeMillis() - time) / 1000.0);

    time = System.currentTimeMillis();
    List<ItemSet> results = fpgrowth.learn();
    System.out.format(
        "%d frequent item sets discovered: %.2f secs.\n",
        results.size(), (System.currentTimeMillis() - time) / 1000.0);

    assertEquals(219725, results.size());
  }
Esempio n. 4
0
  /** Test of learn method, of class FPGrowth. */
  @Test
  public void testPima() {
    System.out.println("pima");

    List<int[]> dataList = new ArrayList<int[]>(1000);

    try {
      InputStream stream =
          getClass().getResourceAsStream("/smile/data/transaction/pima.D38.N768.C2");
      BufferedReader input = new BufferedReader(new InputStreamReader(stream));

      String line;
      for (int nrow = 0; (line = input.readLine()) != null; nrow++) {
        if (line.trim().isEmpty()) {
          continue;
        }

        String[] s = line.split(" ");

        int[] point = new int[s.length];
        for (int i = 0; i < s.length; i++) {
          point[i] = Integer.parseInt(s[i]);
        }

        dataList.add(point);
      }
    } catch (IOException ex) {
      System.err.println(ex);
    }

    int[][] data = dataList.toArray(new int[dataList.size()][]);

    int n = Math.max(data);
    System.out.format("%d transactions, %d items\n", data.length, n);

    long time = System.currentTimeMillis();
    FPGrowth fpgrowth = new FPGrowth(data, 20);
    System.out.format(
        "Done building FP-tree: %.2f secs.\n", (System.currentTimeMillis() - time) / 1000.0);

    time = System.currentTimeMillis();
    long numItemsets = fpgrowth.learn(System.out);
    System.out.format(
        "%d frequent item sets discovered: %.2f secs.\n",
        numItemsets, (System.currentTimeMillis() - time) / 1000.0);

    assertEquals(1803, numItemsets);
    assertEquals(1803, fpgrowth.learn().size());
  }