Skip to content

Commit 95951a5

Browse files
committed
updated feature equals method
1 parent 4131ed7 commit 95951a5

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

niaarm/feature.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import math
2+
3+
14
class Feature:
25
r"""Class representing a feature.
36
@@ -20,19 +23,22 @@ def __init__(self, name, dtype, min_val=None, max_val=None, categories=None):
2023
self.categories = categories
2124

2225
def __eq__(self, other):
23-
return (
24-
self.name == other.name
25-
and self.dtype == other.dtype
26-
and self.min_val == other.min_val
27-
and self.max_val == other.max_val
28-
)
26+
if self.dtype != other.dtype or self.name != other.name:
27+
return False
28+
29+
if self.dtype == "cat":
30+
return self.categories == other.categories
31+
32+
return math.isclose(
33+
self.min_val, other.min_val, rel_tol=1e-6, abs_tol=1e-6
34+
) and math.isclose(self.max_val, other.max_val, rel_tol=1e-6, abs_tol=1e-6)
2935

3036
def __repr__(self):
3137
string = f"{self.name}("
3238
if self.dtype == "cat":
3339
string += f"{self.categories if len(self.categories) != 1 else self.categories[0]})"
3440
else:
35-
if self.min_val == self.max_val:
41+
if math.isclose(self.min_val, self.max_val, rel_tol=1e-6, abs_tol=1e-6):
3642
string += f"{self.min_val})"
3743
else:
3844
string += f"[{self.min_val}, {self.max_val}])"

niaarm/rule.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ def zhang(self):
322322
support = self.support
323323

324324
numerator = support - support_x * support_y
325-
denominator = max(support * (1 - support_x), support_x * (support_y - support))
325+
denominator = (
326+
max(support * (1 - support_x), support_x * (support_y - support))
327+
+ 2.220446049250313e-16
328+
)
326329

327330
return numerator / denominator
328331

0 commit comments

Comments
 (0)