@@ -73,7 +73,9 @@ def find_frequent_itemsets(self) -> List[Dict[frozenset, float]]:
73
73
74
74
total : int = len (self .transactions )
75
75
current_itemsets : Dict [frozenset , float ] = {
76
- k : v / total for k , v in item_counts .items () if v / total >= self .min_support
76
+ k : v / total
77
+ for k , v in item_counts .items ()
78
+ if v / total >= self .min_support
77
79
}
78
80
if current_itemsets :
79
81
self .itemsets .append (current_itemsets )
@@ -92,7 +94,9 @@ def find_frequent_itemsets(self) -> List[Dict[frozenset, float]]:
92
94
candidates .add (union )
93
95
94
96
freq_candidates : Dict [frozenset , float ] = {
95
- c : self ._get_support (c ) for c in candidates if self ._get_support (c ) >= self .min_support
97
+ c : self ._get_support (c )
98
+ for c in candidates
99
+ if self ._get_support (c ) >= self .min_support
96
100
}
97
101
if not freq_candidates :
98
102
break
@@ -103,7 +107,9 @@ def find_frequent_itemsets(self) -> List[Dict[frozenset, float]]:
103
107
104
108
return self .itemsets
105
109
106
- def generate_association_rules (self ) -> List [Tuple [frozenset , frozenset , float , float ]]:
110
+ def generate_association_rules (
111
+ self ,
112
+ ) -> List [Tuple [frozenset , frozenset , float , float ]]:
107
113
"""Generate association rules with min confidence and lift."""
108
114
for level in self .itemsets :
109
115
for itemset in level :
@@ -121,7 +127,11 @@ def generate_association_rules(self) -> List[Tuple[frozenset, frozenset, float,
121
127
conf ,
122
128
lft ,
123
129
)
124
- if rule not in self .rules and conf >= self .min_confidence and lft >= self .min_lift :
130
+ if (
131
+ rule not in self .rules
132
+ and conf >= self .min_confidence
133
+ and lft >= self .min_lift
134
+ ):
125
135
self .rules .append (rule )
126
136
return self .rules
127
137
0 commit comments