source: orange/docs/reference/rst/code/reliability-long.py @ 9681:b278e50a6071

Revision 9681:b278e50a6071, 1.8 KB checked in by Matija Polajnar <matija.polajnar@…>, 2 years ago (diff)

Reliability: add headers to regression test scripts.

Line 
1# Description: Reliability estimation
2# Category:    evaluation
3# Uses:        prostate
4# Referenced:  Orange.evaluation.reliability
5# Classes:     Orange.evaluation.reliability.Learner
6
7import Orange
8
9table = Orange.data.Table("prostate.tab")
10
11knn = Orange.classification.knn.kNNLearner()
12reliability = Orange.evaluation.reliability.Learner(knn)
13
14res = Orange.evaluation.testing.cross_validation([reliability], table)
15
16reliability_res = Orange.evaluation.reliability.get_pearson_r(res)
17
18print
19print "Estimate               r       p"
20for estimate in reliability_res:
21    print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]],
22                                 estimate[0], estimate[1])
23
24reliability = Orange.evaluation.reliability.Learner(knn, estimators=[Orange.evaluation.reliability.SensitivityAnalysis()])
25
26res = Orange.evaluation.testing.cross_validation([reliability], table)
27
28reliability_res = Orange.evaluation.reliability.get_pearson_r(res)
29
30print
31print "Estimate               r       p"
32for estimate in reliability_res:
33    print "%-20s %7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]],
34                                 estimate[0], estimate[1])
35
36indices = Orange.core.MakeRandomIndices2(table, p0=0.7)
37train = table.select(indices, 0)
38test = table.select(indices, 1)
39
40reliability = Orange.evaluation.reliability.Learner(knn, icv=True)
41res = Orange.evaluation.testing.learn_and_test_on_test_data([reliability], train, test)
42
43print
44print "Method used in internal cross-validation: ", Orange.evaluation.reliability.METHOD_NAME[res.results[0].probabilities[0].reliability_estimate[0].method]
45
46top5 = sorted((abs(result.probabilities[0].reliability_estimate[0].estimate), id) for id, result in enumerate(res.results))[:5]
47for estimate, id in top5:
48    print "%7.3f %i" % (estimate, id)
Note: See TracBrowser for help on using the repository browser.