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

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

Moved orange to Orange (part 2)

Line
1# Description: Builds regression models from data and outputs predictions for first five instances
2# Category:    modelling
3# Uses:        housing
4# Classes:     MakeRandomIndices2, MajorityLearner, orngTree.TreeLearner, orange.kNNLearner
5# Referenced:  regression.htm
6
7import orange, orngTree, orngTest, orngStat
8
9data = orange.ExampleTable("../datasets/housing.tab")
10selection = orange.MakeRandomIndices2(data, 0.5)
11train_data = data.select(selection, 0)
12test_data = data.select(selection, 1)
13
14maj = orange.MajorityLearner(train_data)
15maj.name = "default"
16
17rt = orngTree.TreeLearner(train_data, measure="retis", mForPruning=2, minExamples=20)
18rt.name = "reg. tree"
19
20k = 5
21knn = orange.kNNLearner(train_data, k=k)
22knn.name = "k-NN (k=%i)" % k
23
24regressors = [maj, rt, knn]
25
26print "\n%10s " % "original",
27for r in regressors:
28  print "%10s " % r.name,
29print
30
31for i in range(10):
32  print "%10.1f " % test_data[i].getclass(),
33  for r in regressors:
34    print "%10.1f " % r(test_data[i]),
35  print
Note: See TracBrowser for help on using the repository browser.