source: orange/orange/doc/ofb/regression4.py @ 4063:db419d205e37

Revision 4063:db419d205e37, 1.2 KB checked in by blaz <blaz.zupan@…>, 7 years ago (diff)

new example with use of orngStat with new regression scoring measures

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