Skip to content

Commit 9a307bc

Browse files
committed
fix formatting per black
1 parent 85b9129 commit 9a307bc

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

mlxtend/frequent_patterns/association_rules.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,18 @@ def kulczynski_helper(sAC, sA, sC, disAC, disA, disC, dis_int, dis_int_):
143143
kulczynski = (conf_AC + conf_CA) / 2
144144
return kulczynski
145145

146-
def mutual_information_metric_helper(sAC, sA, sC, disAC, disA, disC, dis_int, dis_int_):
146+
def mutual_information_metric_helper(
147+
sAC, sA, sC, disAC, disA, disC, dis_int, dis_int_
148+
):
147149
with np.errstate(divide="ignore", invalid="ignore"):
148150
numerator = sAC
149151
denominator = sA * sC
150152
# MI = log2(s_AC / (s_A * s_C)); returns -inf if any support is 0
151-
mi = np.where((numerator > 0) & (denominator > 0), np.log2(numerator / denominator), -np.inf)
153+
mi = np.where(
154+
(numerator > 0) & (denominator > 0),
155+
np.log2(numerator / denominator),
156+
-np.inf,
157+
)
152158
return mi
153159

154160
def conviction_helper(conf, sC):

mlxtend/frequent_patterns/tests/test_association_rules.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,20 @@ def test_with_empty_dataframe():
544544

545545
def test_mutual_information_metric():
546546
"""Test mutual_information metric returns correct values."""
547-
res_df = association_rules(df_freq_items, len(df), metric="mutual_information", min_threshold=-100)
547+
res_df = association_rules(
548+
df_freq_items, len(df), metric="mutual_information", min_threshold=-100
549+
)
548550
assert "mutual_information" in res_df.columns
549551

550552
# Find the rule (Eggs -> Kidney Beans): sAC=0.6, sA=0.8, sC=1.0
551553
# MI = log2(0.6 / (0.8 * 1.0)) = log2(0.75) approx -0.415
552554
rule = res_df[
553-
res_df["antecedents"].apply(lambda x: x == frozenset({3})) &
554-
res_df["consequents"].apply(lambda x: x == frozenset({5}))
555+
res_df["antecedents"].apply(lambda x: x == frozenset({3}))
556+
& res_df["consequents"].apply(lambda x: x == frozenset({5}))
555557
]
556558
assert len(rule) == 1
557559
import math
560+
558561
expected_mi = math.log2(0.6 / (0.8 * 1.0))
559562
assert abs(rule["mutual_information"].values[0] - expected_mi) < 1e-6
560563

0 commit comments

Comments
 (0)