/** Test of learn method, of class ARM. */ @Test public void testLearn() { System.out.println("learn"); ARM instance = new ARM(itemsets, 3); instance.learn(0.5, System.out); List<AssociationRule> rules = instance.learn(0.5); assertEquals(9, rules.size()); assertEquals(0.6, rules.get(0).support, 1E-2); assertEquals(0.75, rules.get(0).confidence, 1E-2); assertEquals(1, rules.get(0).antecedent.length); assertEquals(3, rules.get(0).antecedent[0]); assertEquals(1, rules.get(0).consequent.length); assertEquals(2, rules.get(0).consequent[0]); assertEquals(0.3, rules.get(4).support, 1E-2); assertEquals(0.6, rules.get(4).confidence, 1E-2); assertEquals(1, rules.get(4).antecedent.length); assertEquals(1, rules.get(4).antecedent[0]); assertEquals(1, rules.get(4).consequent.length); assertEquals(2, rules.get(4).consequent[0]); assertEquals(0.3, rules.get(8).support, 1E-2); assertEquals(0.6, rules.get(8).confidence, 1E-2); assertEquals(1, rules.get(8).antecedent.length); assertEquals(1, rules.get(8).antecedent[0]); assertEquals(2, rules.get(8).consequent.length); assertEquals(3, rules.get(8).consequent[0]); assertEquals(2, rules.get(8).consequent[1]); }
/** Test of learn method, of class ARM. */ @Test public void testLearnKosarak() { 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); ARM instance = new ARM(data, 0.003); long numRules = instance.learn(0.5, System.out); System.out.format("%d association rules discovered\n", numRules); assertEquals(17932, numRules); }
/** Test of learn method, of class ARM. */ @Test public void testLearnPima() { 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); ARM instance = new ARM(data, 20); long numRules = instance.learn(0.9, System.out); System.out.format("%d association rules discovered\n", numRules); assertEquals(6803, numRules); assertEquals(6803, instance.learn(0.9).size()); }