Changeset 8911:4b05190e42b8 in orange


Ignore:
Timestamp:
09/05/11 14:34:56 (3 years ago)
Author:
mocnik <mocnik@…>
Branch:
default
Convert:
ebd48ebdd65fcca8aac06bd5bbd17338b58432ed
Message:

Removed blending support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/evaluation/reliability.py

    r8903 r8911  
    176176from collections import defaultdict 
    177177from itertools import izip 
    178  
    179 import Orange.regression.linear 
    180178 
    181179# Labels and final variables 
     
    745743     
    746744    :rtype: :class:`Orange.evaluation.reliability.Learner` 
     745     
     746    .. function:: internal_cross_validation 
     747     
     748    .. function:: internal_cross_validation_testing 
    747749    """ 
    748750    def __init__(self, box_learner, name="Reliability estimation", 
     
    752754                               Mahalanobis(), 
    753755                               ], 
    754                  blending = False, **kwds): 
     756                 **kwds): 
    755757        self.__dict__.update(kwds) 
    756758        self.name = name 
    757759        self.estimators = estimators 
    758760        self.box_learner = box_learner 
    759         self.blending = blending 
     761        self.blending = False 
    760762         
    761763     
     
    773775        new_domain = None 
    774776         
    775         # Perform blending of the reliability estimates 
    776         if self.blending: 
    777             # Do the internal cross validation to get the estimates on training set 
    778             self.blending = False 
    779             res = Orange.evaluation.testing.cross_validation([self], examples) 
    780             self.blending = True 
    781              
    782             # Create new domain 
    783             new_domain = Orange.data.Domain([Orange.core.FloatVariable(estimate.method_name) for estimate in res.results[0].probabilities[0].reliability_estimate], Orange.core.FloatVariable("pe")) 
    784              
    785             # Create dataset with this domain 
    786             new_dataset = Orange.data.Table(new_domain) 
    787              
    788             for result in res.results: 
    789                 values = [estimate.estimate for estimate in result.probabilities[0].reliability_estimate] + [abs(result.actualClass - result.classes[0])] 
    790                 new_example = Orange.data.Instance(new_domain, values) 
    791                 new_dataset.append(new_example) 
    792              
    793             # Learn some learner on new dataset 
    794             #blender = Orange.classification.svm.SVMLearner() 
    795             #blender.svm_type = blender.Nu_SVR 
    796             blender = Orange.regression.linear.LinearRegressionLearner() 
    797              
    798             blending_classifier = blender(new_dataset) 
    799              
    800             print get_pearson_r(res) 
    801             print blending_classifier 
    802          
    803777        return Classifier(examples, self.box_learner, self.estimators, self.blending, new_domain, blending_classifier) 
    804778     
    805779    def internal_cross_validation(self, examples, folds=10): 
     780        """ Performs the ususal internal cross validation for getting the best 
     781        reliability estimate. Returns the id of the method that scored the  
     782        best. """ 
     783        res = Orange.evaluation.testing.cross_validation([self], examples, folds=folds) 
     784        results = get_pearson_r(res) 
     785        sorted_results = sorted(results) 
     786        return sorted_results[-1][3] 
     787     
     788    def internal_cross_validation_testing(self, examples, folds=10): 
    806789        """ Performs internal cross validation (as in Automatic selection of 
    807790        reliability estimates for individual regression predictions, 
     
    870853            probabilities.reliability_estimate.extend(estimate(example, predicted, probabilities)) 
    871854         
    872         # Do the blending part 
    873         if self.blending: 
    874             # Create an example 
    875             values = [estimate.estimate for estimate in probabilities.reliability_estimate] + ["?"] 
    876             new_example = Orange.data.Instance(self.blending_domain, values) 
    877             blending_value = self.rf_classifier(new_example, Orange.core.GetValue) 
    878             probabilities.reliability_estimate.append(Estimate(blending_value.value, ABSOLUTE, BLENDING_ABSOLUTE)) 
    879              
    880855        # Return the appropriate type of result 
    881856        if result_type == Orange.core.GetValue: 
Note: See TracChangeset for help on using the changeset viewer.