Skip to content

Commit f2b1f8a

Browse files
committed
feat: add Apriori with association rule mining (support, confidence, lift)
1 parent 12e5cb3 commit f2b1f8a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

machine_learning/apriori_algorithm.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
WIKI: https://en.wikipedia.org/wiki/Apriori_algorithm
99
"""
1010

11-
from itertools import combinations
1211
from collections import defaultdict
13-
12+
from itertools import combinations
1413

1514
def load_data() -> list[list[str]]:
1615
"""
@@ -70,8 +69,7 @@ def find_frequent_itemsets(self):
7069
for i in range(len(keys)):
7170
for j in range(i + 1, len(keys)):
7271
union = keys[i] | keys[j]
73-
if len(union) == k:
74-
if all(frozenset(sub) in current_itemsets for sub in combinations(union, k - 1)):
72+
if len(union) == k and all(frozenset(sub) in current_itemsets for sub in combinations(union, k - 1)):
7573
candidates.add(union)
7674

7775
freq_candidates = {c: self._get_support(c) for c in candidates if self._get_support(c) >= self.min_support}

0 commit comments

Comments
 (0)