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

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

Tutorial documentation structure.

Line 
1# Description: Uses cross-validation to compare regression tree and k-nearest neighbors
2# Category:    modelling, evaluation
3# Uses:        housing
4# Classes:     orngStat.MSE, orngTest.crossValidation, MajorityLearner, orngTree.TreeLearner, orange.kNNLearner
5# Referenced:  regression.htm
6
7import orange, orngTree, orngTest, orngStat
8
9data = orange.ExampleTable("housing.tab")
10
11maj = orange.MajorityLearner()
12maj.name = "default"
13rt = orngTree.TreeLearner(measure="retis", mForPruning=2, minExamples=20)
14rt.name = "regression tree"
15k = 5
16knn = orange.kNNLearner(k=k)
17knn.name = "k-NN (k=%i)" % k
18learners = [maj, rt, knn]
19
20data = orange.ExampleTable("housing.tab")
21results = orngTest.crossValidation(learners, data, folds=10)
22mse = orngStat.MSE(results)
23
24print "Learner        MSE"
25for i in range(len(learners)):
26  print "%-15s %5.3f" % (learners[i].name, mse[i])
Note: See TracBrowser for help on using the repository browser.