Skip to content

Commit 356e14d

Browse files
fix division by zero error during acc calculation
1 parent e8691e4 commit 356e14d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

niaarm/rule.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ def __post_init__(self, transactions):
221221
if attribute.dtype != "cat":
222222
feature_min = min_[attribute.name]
223223
feature_max = max_[attribute.name]
224-
acc += (attribute.max_val - attribute.min_val) / (
225-
feature_max - feature_min
226-
)
224+
acc += 1 if feature_max == feature_min \
225+
else (attribute.max_val - attribute.min_val) / (feature_max - feature_min)
227226
contains_antecedent &= transactions[attribute.name] <= attribute.max_val
228227
contains_antecedent &= transactions[attribute.name] >= attribute.min_val
229228
else:
@@ -240,9 +239,8 @@ def __post_init__(self, transactions):
240239
if attribute.dtype != "cat":
241240
feature_min = min_[attribute.name]
242241
feature_max = max_[attribute.name]
243-
acc += (attribute.max_val - attribute.min_val) / (
244-
feature_max - feature_min
245-
)
242+
acc += 1 if feature_max == feature_min \
243+
else (attribute.max_val - attribute.min_val) / (feature_max - feature_min)
246244
contains_consequent &= transactions[attribute.name] <= attribute.max_val
247245
contains_consequent &= transactions[attribute.name] >= attribute.min_val
248246
else:

0 commit comments

Comments
 (0)