source: orange/orange/doc/ofb/accuracy3.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.1 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

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