From d4ff2d4561eed1dd7aba039b8397b32a6cc13737 Mon Sep 17 00:00:00 2001 From: FernandoLpz Date: Wed, 18 Nov 2020 17:13:27 -0600 Subject: [PATCH] Fix bug when converting OSDT leaves into a Text Classifier compatible object --- python/model/gosdt.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/python/model/gosdt.py b/python/model/gosdt.py index 48bc4d7..36aeabe 100644 --- a/python/model/gosdt.py +++ b/python/model/gosdt.py @@ -306,9 +306,24 @@ def __translate__(self, leaves): } else: features = {} + # In next commented section there is a bug when trying to validate if a leaf exists in the "features" dict. Essentially, a "leaf" has + # the form: (feature_1, feature_2, ..., feature_n) and the "keys" and "values" of the "features" dict has the form: + # key = feature + # value = frequency + # So, the condition must be changed in order to evaluate the case when a "feature" from the current "leaf" exists in the "features" dict + # Otherwise, for some specific cases this loop crashes + # ------ Original loop ---------- # + # for leaf in leaves.keys(): + # if not leaf in features: + # for e in leaf: + # features[abs(e)] = 1 + # else: + # features[abs(e)] += 1 + + # ------ Fixed loop ---------- # for leaf in leaves.keys(): - if not leaf in features: - for e in leaf: + for e in leaf: + if abs(e) not in features.keys(): features[abs(e)] = 1 else: features[abs(e)] += 1