Changeset 38:7aabb3dd2321 in orangereliability
 Timestamp:
 10/02/13 15:38:27 (7 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orangecontrib/reliability/__init__.py
r37 r38 899 899 class Stacking: 900 900 901 def __init__(self, stack_learner, estimators , folds=10, save_data=False):901 def __init__(self, stack_learner, estimators=None, folds=10, save_data=False): 902 902 self.stack_learner = stack_learner 903 903 self.estimators = estimators 904 904 self.folds = folds 905 905 self.save_data = save_data 906 if self.estimators is None: 907 self.estimators = [SensitivityAnalysis(), 908 LocalCrossValidation(), 909 BaggingVarianceCNeighbours(), 910 Mahalanobis(), 911 MahalanobisToCenter()] 906 912 907 913 def __call__(self, data, learner): … … 998 1004 class ICV: 999 1005 """ Perform internal cross validation (as in Automatic selection of 1000 1006 reliability estimates for individual regression predictions, 1001 1007 Zoran Bosnic, 2010) and return id of the method 1002 1008 that scored best on this data. 1003 1004 1005 1009 """ 1006 1010 1007 def __init__(self, estimators , folds=10):1011 def __init__(self, estimators=None, folds=10): 1008 1012 self.estimators = estimators 1013 if self.estimators is None: 1014 self.estimators = [SensitivityAnalysis(), 1015 LocalCrossValidation(), 1016 BaggingVarianceCNeighbours(), 1017 Mahalanobis(), 1018 MahalanobisToCenter()] 1009 1019 self.folds = folds 1010 1020 … … 1013 1023 cvi = Orange.data.sample.SubsetIndicesCV(data, self.folds) 1014 1024 sum_of_rs = defaultdict(float) 1025 n_rs = defaultdict(int) 1015 1026 1016 1027 elearner = Learner(learner, estimators=self.estimators) … … 1023 1034 res = Orange.evaluation.testing.learn_and_test_on_test_data([elearner], learn, test) 1024 1035 results = get_pearson_r(res) 1036 1025 1037 for r, p, sa, method in results: 1026 sum_of_rs[(method, sa)] += r 1027 1028 sum_of_rs = sorted(sum_of_rs.items(), key=lambda estimate: estimate[1], reverse=True) 1029 chosen = sum_of_rs[0][0] 1030 print "chosen", chosen 1031 print sum_of_rs 1038 if not math.isnan(r): #ignore NaN values 1039 sum_of_rs[(method, sa)] += r 1040 n_rs[(method, sa)] += 1 1041 1042 avg_rs = [ (k,(sum_of_rs[k]/n_rs[k])) for k in sum_of_rs ] 1043 1044 avg_rs = sorted(avg_rs, key=lambda estimate: estimate[1], reverse=True) 1045 chosen = avg_rs[0][0] 1032 1046 1033 1047 lf = elearner(data) … … 1071 1085 """ 1072 1086 def __init__(self, box_learner, name="Reliability estimation", 1073 estimators=[SensitivityAnalysis(), 1074 LocalCrossValidation(), 1075 BaggingVarianceCNeighbours(), 1076 Mahalanobis(), 1077 MahalanobisToCenter()], 1087 estimators=None, 1078 1088 **kwds): 1079 1089 self.__dict__.update(kwds) 1080 1090 self.name = name 1081 1091 self.estimators = estimators 1092 if self.estimators is None: 1093 self.estimators = [SensitivityAnalysis(), 1094 LocalCrossValidation(), 1095 BaggingVarianceCNeighbours(), 1096 Mahalanobis(), 1097 MahalanobisToCenter()] 1098 1082 1099 self.box_learner = box_learner 1083 1100 self.blending = False
Note: See TracChangeset
for help on using the changeset viewer.