def get_runner_parameters(self) -> Tuple[Optional[Table], Optional[Model], Optional[Type[Score]], int]: score = None if self.model: if version > "3.31.1": # Eventually, keep this line (remove lines 305-306) and # upgrade minimal Orange version to 3.32.0. # Also remove the Orange.version import score = usable_scorers(self.model.domain)[self.score_index] else: var = self.model.domain.class_var score = usable_scorers(var)[self.score_index] return self.data, self.model, score, self.n_repeats
def test_usable_scores(self): classification_scorers = { scorer.name for scorer in usable_scorers(self.iris.domain) } regression_scorers = { scorer.name for scorer in usable_scorers(self.housing.domain) } self.validate_scorer_candidates(classification_scorers, class_type=DiscreteVariable) self.validate_scorer_candidates(regression_scorers, class_type=ContinuousVariable)
def _update_scores(self): model = self.score_table.model model.clear() scorers = usable_scorers(self.class_var) if self.class_var else [] self.score_table.update_header(scorers) errors = [] for inputid, pred in self.predictors.items(): results = self.predictors[inputid].results if not isinstance(results, Results) or results.predicted is None: continue row = [QStandardItem(learner_name(pred.predictor)), QStandardItem("N/A"), QStandardItem("N/A")] for scorer in scorers: item = QStandardItem() try: score = scorer_caller(scorer, results)()[0] item.setText(f"{score:.3f}") except Exception as exc: # pylint: disable=broad-except item.setToolTip(str(exc)) if scorer.name in self.score_table.shown_scores: errors.append(str(exc)) row.append(item) self.score_table.model.appendRow(row) view = self.score_table.view if model.rowCount(): view.setVisible(True) view.ensurePolished() view.setFixedHeight( 5 + view.horizontalHeader().height() + view.verticalHeader().sectionSize(0) * model.rowCount()) else: view.setVisible(False) self.Error.scorer_failed("\n".join(errors), shown=bool(errors))
def _update_scores(self): model = self.score_table.model model.clear() if self.data is None or self.data.domain.class_var is None: scorers = [] else: scorers = usable_scorers(self.data.domain.class_var) self.score_table.update_header(scorers) errors = [] for inputid, pred in self.predictors.items(): name = learner_name(pred.predictor) head = QStandardItem(name) # head.setData(key, Qt.UserRole) row = [head] results = self.predictors[inputid].results if isinstance(results, str): head.setToolTip(results) head.setText("{} (error)".format(name)) head.setForeground(QBrush(Qt.red)) else: for scorer in scorers: item = QStandardItem() try: score = scorer_caller(scorer, results)()[0] item.setText(f"{score:.3f}") except Exception as exc: # pylint: disable=broad-except item.setToolTip(str(exc)) if scorer.name in self.score_table.shown_scores: errors.append(str(exc)) row.append(item) self.score_table.model.appendRow(row) self.Error.scorer_failed("\n".join(errors), shown=bool(errors))
def test_if_deprecation_warning_is_raised(self): with self.assertWarns(OrangeDeprecationWarning): classification_scorers = { scorer.name for scorer in usable_scorers(self.iris.domain.class_var) } with self.assertWarns(OrangeDeprecationWarning): regression_scorers = { scorer.name for scorer in usable_scorers(self.housing.domain.class_var) } # check if we get valid scorers using deprecated approach self.validate_scorer_candidates(classification_scorers, class_type=DiscreteVariable) self.validate_scorer_candidates(regression_scorers, class_type=ContinuousVariable)
def _update_scorers(self): if self.data and self.data.domain.class_var: new_scorers = usable_scorers(self.data.domain.class_var) else: new_scorers = [] # Don't unnecessarily reset the model because this would always reset # comparison_criterion; we alse set it explicitly, though, for clarity if new_scorers != self.scorers: self.scorers = new_scorers self.controls.comparison_criterion.model()[:] = \ [scorer.long_name or scorer.name for scorer in self.scorers] self.comparison_criterion = 0 if self.__pending_comparison_criterion is not None: # Check for the unlikely case that some scorers have been removed # from modules if self.__pending_comparison_criterion < len(self.scorers): self.comparison_criterion = self.__pending_comparison_criterion self.__pending_comparison_criterion = None self._update_compbox_title()
def _update_scorers(self): new_scorers = [] if self.data: new_scorers = usable_scorers(self.data.domain) # Don't unnecessarily reset the combo because this would always reset # comparison_criterion; we also set it explicitly, though, for clarity if new_scorers != self.scorers: self.scorers = new_scorers combo = self.controls.comparison_criterion combo.clear() combo.addItems( [scorer.long_name or scorer.name for scorer in self.scorers]) if self.scorers: self.comparison_criterion = 0 if self.__pending_comparison_criterion is not None: # Check for the unlikely case that some scorers have been removed # from modules if self.__pending_comparison_criterion < len(self.scorers): self.comparison_criterion = self.__pending_comparison_criterion self.__pending_comparison_criterion = None
def _update_scorers(self): if self.data is None or self.data.domain.class_var is None: self.scorers = [] return self.scorers = usable_scorers(self.data.domain.class_var)