source: orange/docs/reference/rst/code/reliability-long.py @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 1.6 KB checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

Line 
1import Orange
2
3prostate = 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], prostate)
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], prostate)
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(prostate, p0=0.7)
31train = prostate.select(indices, 0)
32test = prostate.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.