From c3b2c78fb433a60642486f2c80b8a57f9b9fac78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Primo=C5=BE=20Godec?= Date: Mon, 20 Apr 2020 12:29:56 +0200 Subject: [PATCH] Fix: Rules failed when new_rules empty --- Orange/classification/rules.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Orange/classification/rules.py b/Orange/classification/rules.py index c4e6b3a6357..db9baf1395c 100644 --- a/Orange/classification/rules.py +++ b/Orange/classification/rules.py @@ -795,7 +795,11 @@ def __str__(self): else: cond = "TRUE" - outcome = class_var.name + "=" + class_var.values[self.prediction] + # it is possible that prediction is not set yet - use _ for outcome + outcome = ( + (class_var.name + "=" + class_var.values[self.prediction]) + if self.prediction is not None else "_" + ) return "IF {} THEN {} ".format(cond, outcome) @@ -870,8 +874,8 @@ def rcmp(rule): new_rules = self.search_strategy.refine_rule( X, Y, W, candidate_rule) rules.extend(new_rules) - #remove default rule from list of rules - if best_rule.length == 0: + # remove default rule from list of rules + if best_rule.length == 0 and len(new_rules) > 0: best_rule = new_rules[0] for new_rule in new_rules[1:]: if (new_rule.quality > best_rule.quality and