Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions machine_learning/apriori_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@
>>> prune(itemset, candidates, 3)
[]
"""
# Use a set for O(1) membership and a Counter for multiplicity checks to
# preserve robustness for edge cases and match existing doctest behavior.
itemset_set = {tuple(item) for item in itemset}
itemset_counter = Counter(tuple(item) for item in itemset)
pruned = []
for candidate in candidates:
is_subsequence = True
for item in candidate:
item_tuple = tuple(item)
if (
item_tuple not in itemset_counter
or itemset_counter[item_tuple] < length - 1
):
if item_tuple not in itemset_set or itemset_counter[item_tuple] < length - 1:

Check failure on line 57 in machine_learning/apriori_algorithm.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

machine_learning/apriori_algorithm.py:57:89: E501 Line too long (89 > 88)
is_subsequence = False
break
if is_subsequence:
Expand Down
Loading