source: orange/docs/tutorial/rst/code/classification-other.py @ 11069:1d46879f99cc

Revision 11069:1d46879f99cc, 813 bytes checked in by blaz <blaz.zupan@…>, 15 months ago (diff)

Change data set from housing (wrong!) to voting.

Line 
1import Orange
2import random
3
4data = Orange.data.Table("voting")
5test = Orange.data.Table(random.sample(data, 5))
6train = Orange.data.Table([d for d in data if d not in test])
7
8tree = Orange.regression.tree.TreeLearner(train, same_majority_pruning=1, m_pruning=2)
9tree.name = "tree"
10knn = Orange.classification.knn.kNNLearner(train, k=21)
11knn.name = "k-NN"
12lr = Orange.classification.logreg.LogRegLearner(train)
13lr.name = "lr"
14
15classifiers = [tree, knn, lr]
16
17target = 0
18print "Probabilities for %s:" % data.domain.class_var.values[target]
19print "original class ",
20print " ".join("%-9s" % l.name for l in classifiers)
21
22return_type = Orange.classification.Classifier.GetProbabilities
23for d in test:
24    print "%-15s" % (d.getclass()),
25    print "     ".join("%5.3f" % c(d, return_type)[target] for c in classifiers)
Note: See TracBrowser for help on using the repository browser.