source: orange/docs/reference/rst/code/reliability-long.py @ 9372:aef193695ea9

Revision 9372:aef193695ea9, 1.6 KB checked in by mitar, 2 years ago (diff)

Moved documentation to the separate directory.

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