source: orange-reliability/docs/rst/code/reliability-long.py @ 39:5e0e4eb49fd1

Revision 39:5e0e4eb49fd1, 1.9 KB checked in by markotoplak, 7 months ago (diff)

Updated examples

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
8prostate = Orange.data.Table("prostate.tab")
9
10knn = Orange.classification.knn.kNNLearner()
11reliability = Orange.evaluation.reliability.Learner(knn)
12
13res = Orange.evaluation.testing.cross_validation([reliability], prostate)
14
15reliability_res = Orange.evaluation.reliability.get_pearson_r(res)
16
17print
18print "Estimate               r       p"
19for estimate in reliability_res:
20    print "%-21s%7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]],
21                                 estimate[0], estimate[1])
22
23reliability = Orange.evaluation.reliability.Learner(knn, estimators=[Orange.evaluation.reliability.SensitivityAnalysis()])
24
25res = Orange.evaluation.testing.cross_validation([reliability], prostate)
26
27reliability_res = Orange.evaluation.reliability.get_pearson_r(res)
28
29print
30print "Estimate               r       p"
31for estimate in reliability_res:
32    print "%-21s%7.3f %7.3f" % (Orange.evaluation.reliability.METHOD_NAME[estimate[3]],
33                                 estimate[0], estimate[1])
34
35indices = Orange.data.sample.SubsetIndices2(prostate, p0=0.7)
36train = prostate.select(indices, 0)
37test = prostate.select(indices, 1)
38
39reliability = Orange.evaluation.reliability.Learner(knn, estimators=[Orange.evaluation.reliability.ICV()])
40reliabilityc = reliability(train)
41res = Orange.evaluation.testing.test_on_data([reliabilityc], train, test)
42
43METHOD_NAME = Orange.evaluation.reliability.METHOD_NAME
44
45print
46print "Method used in internal cross-validation: ", METHOD_NAME[reliabilityc.estimation_classifiers[0].chosen[0]]
47
48top5 = sorted((abs(result.probabilities[0].reliability_estimate[0].estimate), id) for id, result in enumerate(res.results))[:5]
49for estimate, id in top5:
50    print "%7.3f %i" % (estimate, id)
Note: See TracBrowser for help on using the repository browser.