if c.innerVariable.varType != orange.VarTypes.Discrete or \ c.outerVariable.varType != orange.VarTypes.Discrete: raise "printTabDelimContingency can only handle discrete contingencies" res = "" for v in c.innerVariable.values: res += "\t%s" % v res += "\n" for i in range(len(c.outerVariable.values)): res += c.outerVariable.values[i] for v in c[i]: res += "\t%5.3f" % v res += "\n" return res orange.setoutput(orange.Contingency, "tab", printTabDelimContingency) data = orange.ExampleTable("monk1") cont = orange.ContingencyAttrClass("e", data) print "\n*** Dump in format 'tab' ***\n" print cont.dump("tab") orange.setoutput(orange.Contingency, "repr", printTabDelimContingency) print "\n*** Print after 'repr' is set ***\n" print cont print "\n*** Reverse-quoting after 'repr' is set ***\n" print `cont` print "\n*** Print after 'str' is set ***\n"
outp += "%s\n" % i else: boundset = func.boundset() for a in boundset: outp += "%s\t" % a.name outp += "%s\n" % func.classVar.name outp += "------\t" * (len(boundset) + 1) + "\n" lc = 0 if len(boundset) == 1: cnt = orngMisc.LimitedCounter( [len(x.values) + 1 for x in boundset]) else: cnt = orngMisc.LimitedCounter([len(x.values) for x in boundset]) for ex in cnt: for i in range(len(ex)): if ex[i] < len(boundset[i].values): outp += "%s\t" % boundset[i].values[ex[i]] else: outp += "?\t", outp += "%s\n" % func.classVar.values[int(func.lookupTable[lc])] lc += 1 return outp for tpe in [ orange.ClassifierByLookupTable, orange.ClassifierByLookupTable2, orange.ClassifierByLookupTable3, orange.ClassifierByExampleTable ]: orange.setoutput(tpe, "tab", printLookupFunction)
if c.innerVariable.varType != orange.VarTypes.Discrete or \ c.outerVariable.varType != orange.VarTypes.Discrete: raise Exception("printTabDelimContingency can only handle discrete contingencies") res = "" for v in c.innerVariable.values: res += "\t%s" % v res += "\n" for i in range(len(c.outerVariable.values)): res += c.outerVariable.values[i] for v in c[i]: res += "\t%5.3f" % v res += "\n" return res orange.setoutput(orange.Contingency, "tab", printTabDelimContingency) data = orange.ExampleTable("monk1") cont = orange.ContingencyAttrClass("e", data) print "\n*** Dump in format 'tab' ***\n" print cont.dump("tab") orange.setoutput(orange.Contingency, "repr", printTabDelimContingency) print "\n*** Print after 'repr' is set ***\n" print cont print "\n*** Reverse-quoting after 'repr' is set ***\n" print `cont` print "\n*** Print after 'str' is set ***\n"
import orange data = orange.ExampleTable("car") classifier = orange.BayesLearner(data) # compute classification accuracy def printTabDelimContingency(c): print c orange.setoutput(orange.BayesClassifier, "tab", printTabDelimContingency) print classifier.dump('tab') correct = 0.0 for ex in data: if classifier(ex) == ex.getclass(): correct += 1 #print "Classification accuracy:", correct/len(data)
import orange from Orange.classification.lookup import \ lookup_from_bound as lookupFromBound, \ lookup_from_function as lookupFromFunction, \ lookup_from_data as lookupFromExamples, \ dump_lookup_function as printLookupFunction for tpe in [orange.ClassifierByLookupTable, orange.ClassifierByLookupTable2, orange.ClassifierByLookupTable3, orange.ClassifierByExampleTable]: orange.setoutput(tpe, "tab", printLookupFunction)