# source:orange/Orange/doc/ofb/accuracy8.py@9671:a7b056375472

Revision 9671:a7b056375472, 1.2 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line
1# Description: Demostration of use of cross-validation as provided in orngEval module
2# Category:    evaluation
3# Uses:        voting.tab
4# Classes:     orngTest.crossValidation
5# Referenced:  c_performance.htm
6
7import orange
8import orngTest, orngStat, orngTree
9
10# set up the learners
11bayes = orange.BayesLearner()
12tree = orngTree.TreeLearner(mForPruning=2)
13bayes.name = "bayes"
14tree.name = "tree"
15learners = [bayes, tree]
16
17# compute accuracies on data
18data = orange.ExampleTable("voting")
19res = orngTest.crossValidation(learners, data, folds=10)
20cm = orngStat.computeConfusionMatrices(res,
21        classIndex=data.domain.classVar.values.index('democrat'))
22
23stat = (('CA', 'CA(res)'),
24        ('Sens', 'sens(cm)'),
25        ('Spec', 'spec(cm)'),
26        ('AUC', 'AUC(res)'),
27        ('IS', 'IS(res)'),
28        ('Brier', 'BrierScore(res)'),
29        ('F1', 'F1(cm)'),
30        ('F2', 'Falpha(cm, alpha=2.0)'),
31        ('MCC', 'MCC(cm)'),
32        ('sPi', 'scottsPi(cm)'),
33        )
34
35scores = [eval("orngStat."+s[1]) for s in stat]
36print
37print "Learner  " + "".join(["%-7s" % s[0] for s in stat])
38for (i, l) in enumerate(learners):
39    print "%-8s " % l.name + "".join(["%5.3f  " % s[i] for s in scores])
Note: See TracBrowser for help on using the repository browser.