@@ -67,7 +67,7 @@ class OWPredictions(OWWidget):
6767 description = "Display predictions of models for an input dataset."
6868 keywords = "predictions"
6969
70- settings_version = 2
70+ settings_version = 3
7171
7272 want_control_area = False
7373
@@ -105,13 +105,13 @@ class Error(OWWidget.Error):
105105 "Show probabilities for classes in data that are also\n "
106106 "known to the model"
107107 ]
108+ TARGET_AVERAGE = "(Average over classes)"
108109
109110 NO_PROBS , DATA_PROBS , MODEL_PROBS , BOTH_PROBS = range (4 )
110111 shown_probs = settings .ContextSetting (NO_PROBS )
111112 selection = settings .Setting ([], schema_only = True )
112113 show_scores = settings .Setting (True )
113- TARGET_AVERAGE = "(Average over classes)"
114- target_class = settings .ContextSetting (TARGET_AVERAGE )
114+ target_class = settings .ContextSetting ("" )
115115 show_probability_errors = settings .ContextSetting (True )
116116 show_reg_errors = settings .ContextSetting (DIFF_ERROR )
117117
@@ -174,7 +174,8 @@ def __init__(self):
174174 gui .widgetLabel (scoreopts , "Target class:" ),
175175 gui .comboBox (
176176 scoreopts , self , "target_class" , items = [], contentsLength = 30 ,
177- sendSelectedValue = True , callback = self ._on_target_changed )
177+ sendSelectedValue = True , callback = self ._on_target_changed ,
178+ emptyString = self .TARGET_AVERAGE )
178179 ]
179180 gui .rubber (scoreopts )
180181
@@ -311,7 +312,7 @@ def _set_target_combos(self):
311312 for i , tip in enumerate (self .PROB_TOOLTIPS ):
312313 prob_combo .setItemData (i , tip , Qt .ToolTipRole )
313314 self .shown_probs = self .DATA_PROBS
314- self .target_class = self . TARGET_AVERAGE
315+ self .target_class = ""
315316 else :
316317 self .shown_probs = self .NO_PROBS
317318 model = prob_combo .model ()
@@ -433,7 +434,7 @@ def _call_predictors(self):
433434
434435 def _update_scores (self ):
435436 model = self .score_table .model
436- if self .is_discrete_class and self .target_class != self . TARGET_AVERAGE :
437+ if self .is_discrete_class and self .target_class :
437438 target = self .class_var .values .index (self .target_class )
438439 else :
439440 target = None
@@ -971,7 +972,8 @@ def merge_data_with_predictions():
971972
972973 self .report_name ("Scores" )
973974 if self .is_discrete_class :
974- self .report_items ([("Target class" , self .target_class )])
975+ self .report_items ([("Target class" ,
976+ self .target_class or self .TARGET_AVERAGE )])
975977 self .report_table (self .score_table .view )
976978
977979 def resizeEvent (self , event ):
@@ -988,6 +990,19 @@ def migrate_settings(cls, settings, version):
988990 if "score_table" in settings :
989991 ScoreTable .migrate_to_show_scores_hints (settings ["score_table" ])
990992
993+ @classmethod
994+ def migrate_context (cls , context , version ):
995+ if version < 3 :
996+ target_class = context .values .get ("target_class" )
997+ # The second condition is a workaround if the workflow is opened
998+ # in a wrong language. Assuming that contexts (and other code) works
999+ # target_class will always appear among values, and if it doesn't,
1000+ # it must be because of averaging.
1001+ # The first condition is also covered by the second, but let it
1002+ # be there for clarity.
1003+ if target_class == cls .TARGET_AVERAGE \
1004+ or target_class not in context .classes :
1005+ context .values ["target_class" ] = ""
9911006
9921007class ItemDelegate (TableDataDelegate ):
9931008 def initStyleOption (self , option , index ):
0 commit comments