Changeset 8911:4b05190e42b8 in orange
 Timestamp:
 09/05/11 14:34:56 (3 years ago)
 Branch:
 default
 Convert:
 ebd48ebdd65fcca8aac06bd5bbd17338b58432ed
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/Orange/evaluation/reliability.py
r8903 r8911 176 176 from collections import defaultdict 177 177 from itertools import izip 178 179 import Orange.regression.linear180 178 181 179 # Labels and final variables … … 745 743 746 744 :rtype: :class:`Orange.evaluation.reliability.Learner` 745 746 .. function:: internal_cross_validation 747 748 .. function:: internal_cross_validation_testing 747 749 """ 748 750 def __init__(self, box_learner, name="Reliability estimation", … … 752 754 Mahalanobis(), 753 755 ], 754 blending = False,**kwds):756 **kwds): 755 757 self.__dict__.update(kwds) 756 758 self.name = name 757 759 self.estimators = estimators 758 760 self.box_learner = box_learner 759 self.blending = blending761 self.blending = False 760 762 761 763 … … 773 775 new_domain = None 774 776 775 # Perform blending of the reliability estimates776 if self.blending:777 # Do the internal cross validation to get the estimates on training set778 self.blending = False779 res = Orange.evaluation.testing.cross_validation([self], examples)780 self.blending = True781 782 # Create new domain783 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 domain786 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 dataset794 #blender = Orange.classification.svm.SVMLearner()795 #blender.svm_type = blender.Nu_SVR796 blender = Orange.regression.linear.LinearRegressionLearner()797 798 blending_classifier = blender(new_dataset)799 800 print get_pearson_r(res)801 print blending_classifier802 803 777 return Classifier(examples, self.box_learner, self.estimators, self.blending, new_domain, blending_classifier) 804 778 805 779 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): 806 789 """ Performs internal cross validation (as in Automatic selection of 807 790 reliability estimates for individual regression predictions, … … 870 853 probabilities.reliability_estimate.extend(estimate(example, predicted, probabilities)) 871 854 872 # Do the blending part873 if self.blending:874 # Create an example875 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 880 855 # Return the appropriate type of result 881 856 if result_type == Orange.core.GetValue:
Note: See TracChangeset
for help on using the changeset viewer.