Commit f5f25a86 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

build subgroups now properly returns a classifier

parent d5aa32b7
...@@ -82,14 +82,15 @@ class SD_learner(orange.Learner): ...@@ -82,14 +82,15 @@ class SD_learner(orange.Learner):
#________________________________________________________________________________________ #________________________________________________________________________________________
class SD_Classifier(orange.Classifier): class SD_Classifier(orange.Classifier):
def __init__(self, data): def __init__(self, data=None):
if type(data) is not orange.ExampleTable: if data:
raise TypeError('Data is not an orange.ExampleTable') if type(data) is not orange.ExampleTable:
if data.domain.classVar.varType != orange.VarTypes.Discrete: raise TypeError('Data is not an orange.ExampleTable')
raise TypeError('Data should have a discrete target variable.') if data.domain.classVar.varType != orange.VarTypes.Discrete:
raise TypeError('Data should have a discrete target variable.')
self.data = data self.data = data
self.majorityClassifier = orange.MajorityLearner(self.data) self.majorityClassifier = data and orange.MajorityLearner(self.data)
self.rulesClass = [] # list of istances SDRules self.rulesClass = [] # list of istances SDRules
self.algorithm = "Subgroup discovery algorithm" self.algorithm = "Subgroup discovery algorithm"
...@@ -125,13 +126,11 @@ class SD_Classifier(orange.Classifier): ...@@ -125,13 +126,11 @@ class SD_Classifier(orange.Classifier):
else : else :
return dist return dist
def addRulesForClass(self, listOfRules, targetClass): def addRulesForClass(self, listOfRules, targetClass):
targetClassRule = SDRule(self.data, targetClass, conditions=[], g =1) targetClassRule = SDRule(self.data, targetClass, conditions=[], g =1)
tmp = SDRules(listOfRules, targetClassRule ) tmp = SDRules(listOfRules, targetClassRule )
self.rulesClass.append( tmp) self.rulesClass.append( tmp)
def printAll(self): def printAll(self):
rulesList = [] rulesList = []
for rClass in self.rulesClass: for rClass in self.rulesClass:
......
...@@ -62,7 +62,7 @@ def build_subgroups_finished(postdata, input_dict, output_dict): ...@@ -62,7 +62,7 @@ def build_subgroups_finished(postdata, input_dict, output_dict):
# add id's # add id's
for i, rule in enumerate(rules.rules): for i, rule in enumerate(rules.rules):
rule.id = i rule.id = i
return {'rules' : rules, 'classifier' : None} return {'rules' : rules, 'classifier' : classifier}
def subgroup_bar_visualization(input_dict): def subgroup_bar_visualization(input_dict):
return {'rules' : None} return {'rules' : None}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment