Skip to content

Commit e4d1ba0

Browse files
JossGeekCopilot
andcommitted
refactor: add type hints to helper functions in Apriori algorithm
Co-authored-by: Copilot <copilot@github.com>
1 parent ac19e67 commit e4d1ba0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

machine_learning/apriori_algorithm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def load_data() -> list[list[str]]:
2727

2828
# ---------- Helpers ----------
2929

30-
def get_support(itemset, transactions):
30+
def get_support(itemset: frozenset, transactions: list[set]):
3131
"""Compute support count of an itemset efficiently."""
3232
return sum(1 for t in transactions if itemset.issubset(t))
3333

3434

35-
def generate_candidates(prev_frequent, k):
35+
def generate_candidates(prev_frequent: set[frozenset], k: int):
3636
"""
3737
Generate candidate itemsets of size k from frequent itemsets of size k-1.
3838
"""
@@ -48,7 +48,7 @@ def generate_candidates(prev_frequent, k):
4848
return candidates
4949

5050

51-
def has_infrequent_subset(candidate, prev_frequent):
51+
def has_infrequent_subset(candidate: frozenset, prev_frequent: set[frozenset]):
5252
"""
5353
Apriori pruning: all (k-1)-subsets must be frequent.
5454
"""

0 commit comments

Comments
 (0)