diff --git a/mlxtend/frequent_patterns/apriori.py b/mlxtend/frequent_patterns/apriori.py index f8c4ac6d7..777ba6ba4 100644 --- a/mlxtend/frequent_patterns/apriori.py +++ b/mlxtend/frequent_patterns/apriori.py @@ -9,44 +9,6 @@ from ..frequent_patterns import fpcommon as fpc -class _FixedLengthTrie: - - """Fixed-length trie (prefix tree). - - Parameters - ---------- - combinations: list of itemsets - All combinations with enough support in the last step - - Attributes - ---------- - root : dict - Root node - """ - __slots__ = ("root") - - def __init__(self, combinations): - self.root = dict() - for combination in combinations: - current = self.root - for item in combination: - try: - current = current[item] - except KeyError: - next_node = dict() - current[item] = next_node - current = next_node - - def __contains__(self, combination): - current = self.root - try: - for item in combination: - current = current[item] - return True - except KeyError: - return False - - def generate_new_combinations(old_combinations): """ Generator of all combinations based on the last state of Apriori algorithm @@ -79,7 +41,7 @@ def generate_new_combinations(old_combinations): """ length = len(old_combinations) - trie = _FixedLengthTrie(old_combinations) + set_old_combinations = set(old_combinations) for i, old_combination in enumerate(old_combinations): head_i = list(old_combination[:-1]) j = i + 1 @@ -94,7 +56,7 @@ def generate_new_combinations(old_combinations): for idx in range(len(candidate) - 2): test_candidate = list(candidate) del test_candidate[idx] - if test_candidate not in trie: + if tuple(test_candidate) not in set_old_combinations: # early exit from for-loop skips else clause just below break else: