Aleš Erjavec avatar Aleš Erjavec committed 8943737

Disable the output if results are from a proportion test.

Comments (0)

Files changed (1)

Orange/OrangeWidgets/Evaluate/OWConfusionMatrix.py

 """
 from OWWidget import *
 import OWGUI
+import orange
 import orngStat, orngTest
 import statc, math
+
 from operator import add
+from collections import defaultdict
+
 from Orange.evaluation.testing import TEST_TYPE_SINGLE
             
 class TransformedLabel(QLabel):
         
         OWGUI.separator(self.controlArea)
 
-        box = OWGUI.widgetBox(self.controlArea, "Output")
+        self.outputBox = box = OWGUI.widgetBox(self.controlArea, "Output")
         OWGUI.checkBox(box, self, "appendPredictions", "Append class predictions", callback = self.sendIf)
         OWGUI.checkBox(box, self, "appendProbabilities", "Append predicted class probabilities", callback = self.sendIf)
         applyButton = OWGUI.button(box, self, "Commit", callback = self.sendData, default=True)
 
     def setTestResults(self, res):
         self.res = res
+        self.warning([0, 1])
+        self.outputBox.setEnabled(True)
+        
         if not res:
             self.matrix = None
             self.table.setRowCount(0)
         if res and res.test_type != TEST_TYPE_SINGLE:
             self.warning(0, "Confusion matrix can be calculated only for single-target prediction problems.")
             return
-        self.warning(0, None)
+        
+        canOutput = True
+        if not hasattr(res, "examples"):
+            self.warning(1, "Results do not have testing instances (Output is disabled).")
+            canOutput = False
+        elif not isinstance(res.examples, orange.ExampleTable):
+            self.warning(1, "Output for results from 'Proportion test' is not supported.")
+            canOutput = False
+            
+        self.outputBox.setEnabled(canOutput) 
         
         self.matrix = orngStat.confusionMatrices(res, -2)
 
             return
 
         learnerI = self.selectedLearner[0]
-        selectionIndices = [i for i, rese in enumerate(res.results) if (rese.actualClass, rese.classes[learnerI]) in selected]
-        data = res.examples.getitemsref(selectionIndices)
         
-        if self.appendPredictions or self.appendProbabilities:
+        data = None
+        if hasattr(res, "examples") and isinstance(res.examples, orange.ExampleTable):
+            selectionIndices = [i for i, rese in enumerate(res.results) if (rese.actualClass, rese.classes[learnerI]) in selected]
+            data = res.examples.getitemsref(selectionIndices)
+        
+        if data is not None and (self.appendPredictions or self.appendProbabilities):
             domain = orange.Domain(data.domain.attributes, data.domain.classVar)
             domain.addmetas(data.domain.getmetas())
             data = orange.ExampleTable(domain, data)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.