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

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

Tutorial documentation structure.

Line
1# Description: Read data, learn several models (bayes, kNN, decision tree) and for all models output class probabilities they return for first few instances
2# Category:    modelling
3# Uses:        voting.tab
4# Classes:     MajorityLearner, BayesLearner, orngTree.TreeLearner, kNNLearner
5# Referenced:  c_otherclass.htm
6
7import orange, orngTree
8data = orange.ExampleTable("voting")
9
10# setting up the classifiers
11majority = orange.MajorityLearner(data)
12bayes = orange.BayesLearner(data)
13tree = orngTree.TreeLearner(data, sameMajorityPruning=1, mForPruning=2)
14knn = orange.kNNLearner(data, k=21)
15
16majority.name="Majority"; bayes.name="Naive Bayes";
17tree.name="Tree"; knn.name="kNN"
18
19classifiers = [majority, bayes, tree, knn]
20
22print "Possible classes:", data.domain.classVar.values
23print "Probability for republican:"
24print "Original Class",
25for l in classifiers:
26    print "%-13s" % (l.name),
27print
28
29# classify first 10 instances and print probabilities
30for example in data[:10]:
31    print "(%-10s)  " % (example.getclass()),
32    for c in classifiers:
33        p = apply(c, [example, orange.GetProbabilities])
34        print "%5.3f        " % (p[0]),
35    print
Note: See TracBrowser for help on using the repository browser.