# source:orange/Orange/testing/regression/tests_20/modules_statExamples-regression.py@9952:986e9cd806f4

Revision 9952:986e9cd806f4, 1.1 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line
1# Description: Demostrates the use of regression scores
2# Category:    evaluation
3# Uses:        housing.tab
4# Referenced:  orngStat.htm
5
6import orange
7import orngRegression as r
8import orngTree
9import orngStat, orngTest
10
11data = orange.ExampleTable("housing")
12
13# definition of regressors
14lr = r.LinearRegressionLearner(name="lr")
15rt = orngTree.TreeLearner(measure="retis", mForPruning=2,
16                          minExamples=20, name="rt")
17maj = orange.MajorityLearner(name="maj")
18knn = orange.kNNLearner(k=10, name="knn")
19
20learners = [maj, rt, knn, lr]
21
22# cross validation, selection of scores, report of results
23results = orngTest.crossValidation(learners, data, folds=3)
24scores = [("MSE", orngStat.MSE),   ("RMSE", orngStat.RMSE),
25          ("MAE", orngStat.MAE),   ("RSE", orngStat.RSE),
26          ("RRSE", orngStat.RRSE), ("RAE", orngStat.RAE),
27          ("R2", orngStat.R2)]
28
29print "Learner   " + "".join(["%-8s" % s[0] for s in scores])
30for i in range(len(learners)):
31    print "%-8s " % learners[i].name + \
32    "".join(["%7.3f " % s[1](results)[i] for s in scores])
Note: See TracBrowser for help on using the repository browser.