Example #1
0
    def testThreeFrequentItemset(self):
        rows = [
            ['a', 'b', 'c', 'd'],
            ['a', 'b', 'c', 'e'],
            ['a', 'b', 'd', 'f'],
        ]
        actual = association_rules.find_frequent_itemsets(rows, 2, 10)

        expected = [
            association_rules.Itemset(['a'], 3),
            association_rules.Itemset(['b'], 3),
            association_rules.Itemset(['c'], 2),
            association_rules.Itemset(['d'], 2),
            association_rules.Itemset(['a', 'b'], 3),
            association_rules.Itemset(['a', 'c'], 2),
            association_rules.Itemset(['a', 'd'], 2),
            association_rules.Itemset(['b', 'c'], 2),
            association_rules.Itemset(['b', 'd'], 2),
            association_rules.Itemset(['a', 'b', 'c'], 2),
            association_rules.Itemset(['a', 'b', 'd'], 2),
        ]
        self.assertEqual(len(expected), len(actual))
        for i in range(len(expected)):
            e = expected[i]
            a = actual[i]
            self.assertEqual(e, a, '%s != %s' % (str(e), str(a)))
    def testUnorderedTwoFrequentItemset(self):
        rows = [["b", "a"], ["c", "b"], ["a", "b"]]
        actual = association_rules.find_frequent_itemsets(rows, 2, 10)

        expected = [
            association_rules.Itemset(["a"], 2),
            association_rules.Itemset(["b"], 3),
            association_rules.Itemset(["a", "b"], 2),
        ]
        self.assertEqual(expected, actual)
Example #3
0
    def testOneFrequentItemset(self):
        rows = [
            ['a'],
            ['a'],
            ['b'],
        ]
        actual = association_rules.find_frequent_itemsets(rows, 2, 10)

        expected = [
            association_rules.Itemset(['a'], 2),
        ]
        self.assertEqual(expected, actual)
    def testThreeFrequentItemset(self):
        rows = [["a", "b", "c", "d"], ["a", "b", "c", "e"], ["a", "b", "d", "f"]]
        actual = association_rules.find_frequent_itemsets(rows, 2, 10)

        expected = [
            association_rules.Itemset(["a"], 3),
            association_rules.Itemset(["b"], 3),
            association_rules.Itemset(["c"], 2),
            association_rules.Itemset(["d"], 2),
            association_rules.Itemset(["a", "b"], 3),
            association_rules.Itemset(["a", "c"], 2),
            association_rules.Itemset(["a", "d"], 2),
            association_rules.Itemset(["b", "c"], 2),
            association_rules.Itemset(["b", "d"], 2),
            association_rules.Itemset(["a", "b", "c"], 2),
            association_rules.Itemset(["a", "b", "d"], 2),
        ]
        self.assertEqual(len(expected), len(actual))
        for i in range(len(expected)):
            e = expected[i]
            a = actual[i]
            self.assertEqual(e, a, "%s != %s" % (str(e), str(a)))
Example #5
0
 def testEmpty(self):
     actual = association_rules.find_frequent_itemsets([], 2, 10)
     self.assertEqual([], actual)
    def testOneFrequentItemset(self):
        rows = [["a"], ["a"], ["b"]]
        actual = association_rules.find_frequent_itemsets(rows, 2, 10)

        expected = [association_rules.Itemset(["a"], 2)]
        self.assertEqual(expected, actual)
 def testEmpty(self):
     actual = association_rules.find_frequent_itemsets([], 2, 10)
     self.assertEqual([], actual)