def print_results(learners, results): # output the results print "Learner CA IS Brier AUC" for i in range(len(learners)): print "%-8s %5.4f %5.3f %5.3f %5.3f" % ( learners[i].name, orngStat.CA(results)[i], orngStat.IS(results)[i], orngStat.BrierScore(results)[i], orngStat.AUC(results)[i])
def cforange_brier_score(input_dict): import orngStat results = input_dict['results'] if input_dict['reportSE']=='true': reportSE = True else: reportSE = False BSs = orngStat.BrierScore(results,reportSE=reportSE) if len(BSs)==1: BSs = BSs[0] output_dict = {} output_dict['bs']=BSs return output_dict
tree = orange.C45Learner(data, m=100) for i in data[:5]: print tree(i), i.getclass() print "\n\nC4.5 with minObjs=100" tree = orange.C45Learner(data, minObjs=100) for i in data[:5]: print tree(i), i.getclass() print "\n\nC4.5 with -m 1 and -s" lrn = orange.C45Learner() lrn.commandline("-m 1 -s") tree = lrn(data) for i in data: if i.getclass() != tree(i): print i, tree(i) import orngC45 tree = orange.C45Learner(data) orngC45.printTree(tree) print import orngStat, orngTest res = orngTest.crossValidation( [orange.C45Learner(), orange.C45Learner(convertToOrange=1)], data) print "Classification accuracy: %5.3f (converted to tree: %5.3f)" % tuple( orngStat.CA(res)) print "Brier score: %5.3f (converted to tree: %5.3f)" % tuple( orngStat.BrierScore(res))
# Description: Demostration of use of cross-validation as provided in orngEval module # Category: evaluation # Uses: voting.tab # Classes: orngTest.crossValidation # Referenced: c_performance.htm import orange, orngTest, orngStat, orngTree # set up the learners bayes = orange.BayesLearner() tree = orngTree.TreeLearner(mForPruning=2) bayes.name = "bayes" tree.name = "tree" learners = [bayes, tree] # compute accuracies on data data = orange.ExampleTable("voting") results = orngTest.crossValidation(learners, data, folds=10) # output the results print "Learner CA IS Brier AUC" for i in range(len(learners)): print "%-8s %5.3f %5.3f %5.3f %5.3f" % (learners[i].name, \ orngStat.CA(results)[i], orngStat.IS(results)[i], orngStat.BrierScore(results)[i], orngStat.AUC(results)[i])
learners = [orange.BayesLearner(name = "bayes"), orngTree.TreeLearner(name="tree"), orange.MajorityLearner(name="majrty")] voting = orange.ExampleTable("voting") res = orngTest.crossValidation(learners, voting) vehicle = orange.ExampleTable("vehicle") resVeh = orngTest.crossValidation(learners, vehicle) import orngStat CAs = orngStat.CA(res) APs = orngStat.AP(res) Briers = orngStat.BrierScore(res) ISs = orngStat.IS(res) print print "method\tCA\tAP\tBrier\tIS" for l in range(len(learners)): print "%s\t%5.3f\t%5.3f\t%5.3f\t%6.3f" % (learners[l].name, CAs[l], APs[l], Briers[l], ISs[l]) CAs = orngStat.CA(res, reportSE=True) APs = orngStat.AP(res, reportSE=True) Briers = orngStat.BrierScore(res, reportSE=True) ISs = orngStat.IS(res, reportSE=True) print print "method\tCA\tAP\tBrier\tIS"
bayes = orange.BayesLearner() tree = orngTree.TreeLearner(mForPruning=2) bayes.name = "bayes" tree.name = "tree" learners = [bayes, tree] # compute accuracies on data data = orange.ExampleTable("voting") res = orngTest.crossValidation(learners, data, folds=10) cm = orngStat.computeConfusionMatrices( res, classIndex=data.domain.classVar.values.index('democrat')) stat = ( ('CA', lambda res, cm: orngStat.CA(res)), ('Sens', lambda res, cm: orngStat.sens(cm)), ('Spec', lambda res, cm: orngStat.spec(cm)), ('AUC', lambda res, cm: orngStat.AUC(res)), ('IS', lambda res, cm: orngStat.IS(res)), ('Brier', lambda res, cm: orngStat.BrierScore(res)), ('F1', lambda res, cm: orngStat.F1(cm)), ('F2', lambda res, cm: orngStat.Falpha(cm, alpha=2.0)), ('MCC', lambda res, cm: orngStat.MCC(cm)), ('sPi', lambda res, cm: orngStat.scottsPi(cm)), ) scores = [s[1](res, cm) for s in stat] print print "Learner " + "".join(["%-7s" % s[0] for s in stat]) for (i, l) in enumerate(learners): print "%-8s " % l.name + "".join(["%5.3f " % s[i] for s in scores])
# Description: Demonstrates the use of random forests from orngEnsemble module # Category: classification, ensembles # Classes: RandomForestLearner # Uses: bupa.tab # Referenced: orngEnsemble.htm import orange, orngTree, orngEnsemble data = orange.ExampleTable('bupa.tab') tree = orngTree.TreeLearner(minExamples=2, mForPrunning=2, \ sameMajorityPruning=True, name='tree') forest = orngEnsemble.RandomForestLearner(trees=50, name="forest") learners = [tree, forest] import orngTest, orngStat results = orngTest.crossValidation(learners, data, folds=3) print "Learner CA Brier AUC" for i in range(len(learners)): print "%-8s %5.3f %5.3f %5.3f" % (learners[i].name, \ orngStat.CA(results)[i], orngStat.BrierScore(results)[i], orngStat.AUC(results)[i])