Skip to content

Commit

Permalink
Removing unnecessary conditions from rules
Browse files Browse the repository at this point in the history
  • Loading branch information
vauxgomes committed Oct 12, 2022
1 parent f1d6ce7 commit 9cfcf56
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lad/rulegenerator/eager.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,28 @@ def fit(self, Xbin, y):

def __adjust(self):
for r in self.__rules:
__cutpoints = [self.__cutpoints[i] for i in self.__selected[r['attributes']]]
conditions = {}
cutpoints = [self.__cutpoints[i] for i in self.__selected[r['attributes']]]

for i, (att, value) in enumerate(cutpoints):
condition = conditions.get(att, {})
symbol = r['conditions'][i] # True: <=, False: >

if symbol: condition[symbol] = min(value, condition.get(symbol, value))
else: condition[symbol] = max(value, condition.get(symbol, value))

conditions[att] = condition

r['attributes'].clear()
r['conditions'].clear()
r['values'] = []

for att in conditions:
for condition in conditions[att]:
r['attributes'].append(att)
r['conditions'].append(condition == '<=')
r['values'].append(conditions[att][condition])

for c in __cutpoints:
r['attributes'].append(c[0])
r['values'].append(c[1])

self.__rules.sort(key=lambda x: x['label'])

def __get_stats(self, Xbin, y, instance, attributes):
Expand Down

0 comments on commit 9cfcf56

Please sign in to comment.