Commits

Anonymous committed 7aabb3d

Added default estimators for ICV and Stacking. Fixed a bug in ICV if a correction is "nan".

  • Participants
  • Parent commits 11955f5

Comments (0)

Files changed (1)

File orangecontrib/reliability/__init__.py

 
 class Stacking:
 
-    def __init__(self, stack_learner, estimators, folds=10, save_data=False):
+    def __init__(self, stack_learner, estimators=None, folds=10, save_data=False):
         self.stack_learner = stack_learner
         self.estimators = estimators
         self.folds = folds
         self.save_data = save_data
+        if self.estimators is None:
+             self.estimators = [SensitivityAnalysis(),
+                           LocalCrossValidation(),
+                           BaggingVarianceCNeighbours(),
+                           Mahalanobis(),
+                           MahalanobisToCenter()]
     
     def __call__(self, data, learner):
 
 
 class ICV:
     """ Perform internal cross validation (as in Automatic selection of
-     reliability estimates for individual regression predictions,
+    reliability estimates for individual regression predictions,
     Zoran Bosnic, 2010) and return id of the method
     that scored best on this data.
-
-
     """
   
-    def __init__(self, estimators, folds=10):
+    def __init__(self, estimators=None, folds=10):
         self.estimators = estimators
+        if self.estimators is None:
+             self.estimators = [SensitivityAnalysis(),
+                           LocalCrossValidation(),
+                           BaggingVarianceCNeighbours(),
+                           Mahalanobis(),
+                           MahalanobisToCenter()]
         self.folds = folds
     
     def __call__(self, data, learner):
 
         cvi = Orange.data.sample.SubsetIndicesCV(data, self.folds)
         sum_of_rs = defaultdict(float)
+        n_rs = defaultdict(int)
 
         elearner = Learner(learner, estimators=self.estimators)
 
 
             res = Orange.evaluation.testing.learn_and_test_on_test_data([elearner], learn, test)
             results = get_pearson_r(res)
+    
             for r, p, sa, method in results:
-                sum_of_rs[(method, sa)] += r 
+                if not math.isnan(r): #ignore NaN values
+                    sum_of_rs[(method, sa)] += r 
+                    n_rs[(method, sa)] += 1 
 
-        sum_of_rs = sorted(sum_of_rs.items(), key=lambda estimate: estimate[1], reverse=True)
-        chosen = sum_of_rs[0][0]
-        print "chosen", chosen
-        print sum_of_rs
+        avg_rs = [ (k,(sum_of_rs[k]/n_rs[k])) for k in sum_of_rs ]
+
+        avg_rs = sorted(avg_rs, key=lambda estimate: estimate[1], reverse=True)
+        chosen = avg_rs[0][0]
 
         lf = elearner(data)
         return ICVClassifier(chosen, lf)
     :rtype: :class:`Orange.evaluation.reliability.Learner`
     """
     def __init__(self, box_learner, name="Reliability estimation",
-                 estimators=[SensitivityAnalysis(),
-                             LocalCrossValidation(),
-                             BaggingVarianceCNeighbours(),
-                             Mahalanobis(),
-                             MahalanobisToCenter()],
+                 estimators=None,
                  **kwds):
         self.__dict__.update(kwds)
         self.name = name
         self.estimators = estimators
+        if self.estimators is None:
+             self.estimators = [SensitivityAnalysis(),
+                           LocalCrossValidation(),
+                           BaggingVarianceCNeighbours(),
+                           Mahalanobis(),
+                           MahalanobisToCenter()]
+ 
         self.box_learner = box_learner
         self.blending = False