Commits

Matija Polajnar committed dc1520d

Add reference method for classification.

  • Participants
  • Parent commits 9679301

Comments (0)

Files changed (1)

File _reliability/__init__.py

 ICV_METHOD = 10
 MAHAL_TO_CENTER_ABSOLUTE = 13
 DENS_ABSOLUTE = 14
+ERR_ABSOLUTE = 15
 
 # Type of estimator constant
 SIGNED = 0
                3: "BAGV absolute", 4: "CNK signed", 5: "CNK absolute",
                6: "LCV absolute", 7: "BVCK_absolute", 8: "Mahalanobis absolute",
                9: "BLENDING absolute", 10: "ICV", 11: "RF Variance", 12: "RF Std",
-               13: "Mahalanobis to center", 14: "Density based"}
+               13: "Mahalanobis to center", 14: "Density based", 15: "Reference expected error"}
 
 select_with_repeat = Orange.core.MakeRandomIndicesMultiple()
 select_with_repeat.random_generator = Orange.misc.Random()
                 Estimate(SAbias, SIGNED, SABIAS_SIGNED),
                 Estimate(abs(SAbias), ABSOLUTE, SABIAS_ABSOLUTE)]
 
+
+
+class ReferenceExpectedError:
+
+    def __init__(self, name="reference"):
+        self.name = name
+
+    def __call__(self, instances, learner):
+        classifier = learner(instances)
+        return ReferenceExpectedErrorClassifier(classifier)
+
+    
+class ReferenceExpectedErrorClassifier:
+
+    def __init__(self, classifier):
+        self.classifier = classifier
+
+    def __call__(self, instance, *args):
+        y_hat = max(self.classifier(instance, Orange.classification.Classifier.GetProbabilities))
+        return [Estimate(2 * y_hat * (1 - y_hat), ABSOLUTE, ERR_ABSOLUTE)]
+
+    
+
 class BaggingVariance:
     """