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

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

Moved orange to Orange (part 2)

Line 
1# Description: Set a number of learners, for each build a classifier from the data and determine classification accuracy
2# Category:    evaluation
3# Uses:        voting.tab
4# Referenced:  c_performance.htm
5
6import orange, orngTree
7
8def accuracy(test_data, classifiers):
9    correct = [0.0]*len(classifiers)
10    for ex in test_data:
11        for i in range(len(classifiers)):
12            if classifiers[i](ex) == ex.getclass():
13                correct[i] += 1
14    for i in range(len(correct)):
15        correct[i] = correct[i] / len(test_data)
16    return correct
17
18# set up the classifiers
19data = orange.ExampleTable("voting")
20bayes = orange.BayesLearner(data)
21bayes.name = "bayes"
22tree = orngTree.TreeLearner(data);
23tree.name = "tree"
24classifiers = [bayes, tree]
25
26# compute accuracies
27acc = accuracy(data, classifiers)
28print "Classification accuracies:"
29for i in range(len(classifiers)):
30    print classifiers[i].name, acc[i]
Note: See TracBrowser for help on using the repository browser.