source:orange/docs/tutorial/rst/code/accuracy8.py@9374:59bac7ddd8a2

Revision 9374:59bac7ddd8a2, 1.4 KB checked in by mitar, 2 years ago (diff)

Tutorial documentation structure.

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', lambda res,cm: orngStat.CA(res)),
24        ('Sens', lambda res,cm: orngStat.sens(cm)),
25        ('Spec', lambda res,cm: orngStat.spec(cm)),
26        ('AUC', lambda res,cm: orngStat.AUC(res)),
27        ('IS', lambda res,cm: orngStat.IS(res)),
28        ('Brier', lambda res,cm: orngStat.BrierScore(res)),
29        ('F1', lambda res,cm: orngStat.F1(cm)),
30        ('F2', lambda res,cm: orngStat.Falpha(cm, alpha=2.0)),
31        ('MCC', lambda res,cm: orngStat.MCC(cm)),
32        ('sPi', lambda res,cm: orngStat.scottsPi(cm)),
33        )
34
35scores = [s[1](res,cm) 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.