def lookupFromExamples(examples, weight = 0, learnerForUnknown = None): if len(examples.domain.attributes) <= 3: lookup = lookupFromBound(examples.domain.classVar, examples.domain.attributes) lookupTable = lookup.lookupTable for example in examples: ind = lookup.getindex(example) if not lookupTable[ind].isSpecial() and (lookupTable[ind] != example.getclass()): break lookupTable[ind] = example.getclass() else: return lookup # there are ambiguities; a backup plan is ClassifierByExampleTable, let it deal with them return orange.LookupLearner(examples, weight, learnerForUnknown = learnerForUnknown) else: return orange.LookupLearner(examples, weight, learnerForUnknown = learnerForUnknown)
def lookupFromFunction(attribute, bound, function): """ Constructs ClassifierByExampleTable or ClassifierByLookupTable mirroring the given function """ lookup = lookupFromBound(attribute, bound) if lookup: lookup.lookupTable = [orange.Value(attribute, function(attributes)) for attributes in orngMisc.LimitedCounter([len(attr.values) for attr in bound])] return lookup else: examples = orange.ExampleTable(orange.Domain(bound, attribute)) for attributes in orngMisc.LimitedCounter([len(attr.values) for attr in dom.attributes]): examples.append(orange.Example(dom, attributes + [function(attributes)])) return orange.LookupLearner(examples)
def lookup_learner(input_dict): import orange output_dict = {} output_dict['lookupout'] = orange.LookupLearner( name="Lookup Classifier (Orange)") return output_dict
# Description: Shows how to construct an orange.ClassifierFromExampleTable # Category: classification, lookup classifiers, constructive induction, feature construction # Classes: ClassifierByExampleTable, LookupLearner # Uses: monk1 # Referenced: lookup.htm import orange data = orange.ExampleTable("monk1") a, b, e = data.domain["a"], data.domain["b"], data.domain["e"] data_s = data.select([a, b, e, data.domain.classVar]) abe = orange.LookupLearner(data_s) print len(data_s) print len(abe.sortedExamples) for i in abe.sortedExamples[:10]: print i print for i in abe.sortedExamples[:10]: print i, i.getclass().svalue print y2 = orange.EnumVariable("y2", values=["0", "1"]) abe2 = orange.LookupLearner(y2, [a, b, e], data) for i in abe2.sortedExamples[:10]: print i, i.getclass().svalue print