From 98b35f4e9222f4f9c3aca7e9729d64b0bfc6f5d7 Mon Sep 17 00:00:00 2001 From: janezd Date: Thu, 10 Oct 2024 17:50:07 +0200 Subject: [PATCH] Ada Boost: Remove option 'algorithm' from the widget --- Orange/widgets/model/owadaboost.py | 50 ++++++++----------- Orange/widgets/model/tests/test_owadaboost.py | 3 -- i18n/si/msgs.jaml | 18 ++----- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/Orange/widgets/model/owadaboost.py b/Orange/widgets/model/owadaboost.py index 12836889b0c..0a0ed5778c9 100644 --- a/Orange/widgets/model/owadaboost.py +++ b/Orange/widgets/model/owadaboost.py @@ -1,4 +1,5 @@ from AnyQt.QtCore import Qt +from AnyQt.QtWidgets import QFormLayout, QLabel from Orange.base import Learner from Orange.data import Table @@ -27,14 +28,11 @@ class OWAdaBoost(OWBaseLearner): class Inputs(OWBaseLearner.Inputs): learner = Input("Learner", Learner) - #: Algorithms for classification problems - algorithms = ["SAMME", "SAMME.R"] #: Losses for regression problems losses = ["Linear", "Square", "Exponential"] n_estimators = Setting(50) learning_rate = Setting(1.) - algorithm_index = Setting(1) loss_index = Setting(0) use_random_seed = Setting(False) random_seed = Setting(0) @@ -46,36 +44,36 @@ class Error(OWBaseLearner.Error): def add_main_layout(self): # this is part of init, pylint: disable=attribute-defined-outside-init - box = gui.widgetBox(self.controlArea, "Parameters") + grid = QFormLayout() + box = gui.widgetBox(self.controlArea, box=True, orientation=grid) self.base_estimator = self.DEFAULT_BASE_ESTIMATOR - self.base_label = gui.label( - box, self, "Base estimator: " + self.base_estimator.name.title()) + self.base_label = QLabel(self.base_estimator.name.title()) + grid.addRow("Base estimator:", self.base_label) self.n_estimators_spin = gui.spin( - box, self, "n_estimators", 1, 10000, label="Number of estimators:", - alignment=Qt.AlignRight, controlWidth=80, + None, self, "n_estimators", 1, 10000, + controlWidth=80, alignment=Qt.AlignRight, callback=self.settings_changed) + grid.addRow("Number of estimators:", self.n_estimators_spin) + self.learning_rate_spin = gui.doubleSpin( - box, self, "learning_rate", 1e-5, 1.0, 1e-5, - label="Learning rate:", decimals=5, alignment=Qt.AlignRight, - controlWidth=80, callback=self.settings_changed) + None, self, "learning_rate", 1e-5, 1.0, 1e-5, decimals=5, + alignment=Qt.AlignRight, + callback=self.settings_changed) + grid.addRow("Learning rate:", self.learning_rate_spin) + + self.reg_algorithm_combo = gui.comboBox( + None, self, "loss_index", items=self.losses, + callback=self.settings_changed) + grid.addRow("Loss (regression):", self.reg_algorithm_combo) + + box = gui.widgetBox(self.controlArea, box="Reproducibility") self.random_seed_spin = gui.spin( box, self, "random_seed", 0, 2 ** 31 - 1, controlWidth=80, label="Fixed seed for random generator:", alignment=Qt.AlignRight, callback=self.settings_changed, checked="use_random_seed", checkCallback=self.settings_changed) - # Algorithms - box = gui.widgetBox(self.controlArea, "Boosting method") - self.cls_algorithm_combo = gui.comboBox( - box, self, "algorithm_index", label="Classification algorithm:", - items=self.algorithms, - orientation=Qt.Horizontal, callback=self.settings_changed) - self.reg_algorithm_combo = gui.comboBox( - box, self, "loss_index", label="Regression loss function:", - items=self.losses, - orientation=Qt.Horizontal, callback=self.settings_changed) - def create_learner(self): if self.base_estimator is None: return None @@ -85,7 +83,6 @@ def create_learner(self): learning_rate=self.learning_rate, random_state=self.random_seed, preprocessors=self.preprocessors, - algorithm=self.algorithms[self.algorithm_index], loss=self.losses[self.loss_index].lower()) @Inputs.learner @@ -97,18 +94,15 @@ def set_base_learner(self, learner): # Clear the error and reset to default base learner self.Error.no_weight_support() self.base_estimator = None - self.base_label.setText("Base estimator: INVALID") + self.base_label.setText("INVALID") else: self.base_estimator = learner or self.DEFAULT_BASE_ESTIMATOR - self.base_label.setText( - "Base estimator: %s" % self.base_estimator.name.title()) + self.base_label.setText(self.base_estimator.name.title()) self.learner = self.model = None def get_learner_parameters(self): return (("Base estimator", self.base_estimator), ("Number of estimators", self.n_estimators), - ("Algorithm (classification)", self.algorithms[ - self.algorithm_index].capitalize()), ("Loss (regression)", self.losses[ self.loss_index].capitalize())) diff --git a/Orange/widgets/model/tests/test_owadaboost.py b/Orange/widgets/model/tests/test_owadaboost.py index 13ef04e501d..0a1e875d2bd 100644 --- a/Orange/widgets/model/tests/test_owadaboost.py +++ b/Orange/widgets/model/tests/test_owadaboost.py @@ -14,9 +14,6 @@ def setUp(self): OWAdaBoost, stored_settings={"auto_apply": False}) self.init() self.parameters = [ - ParameterMapping('algorithm', self.widget.cls_algorithm_combo, - self.widget.algorithms, - problem_type="classification"), ParameterMapping('loss', self.widget.reg_algorithm_combo, [x.lower() for x in self.widget.losses], problem_type="regression"), diff --git a/i18n/si/msgs.jaml b/i18n/si/msgs.jaml index c3084815f14..d5bc6e39c9b 100644 --- a/i18n/si/msgs.jaml +++ b/i18n/si/msgs.jaml @@ -2017,7 +2017,6 @@ ensembles/ada_boost.py: '`base_estimator` is deprecated (to be removed in 3.39): use `estimator` instead.': false class `SklAdaBoostClassificationLearner`: def `__init__`: - SAMME.R: false deprecated: false class `SklAdaBoostRegressionLearner`: def `__init__`: @@ -9507,35 +9506,28 @@ widgets/model/owadaboost.py: adaboost, boost: adaboost, boost class `Inputs`: Learner: Učni algoritem - SAMME: true - SAMME.R: true Linear: Linearna Square: Kvadratna Exponential: Eksponentna class `Error`: The base learner does not support weights.: Učni algoritem ne podpira uteži. def `add_main_layout`: - Parameters: Parametri - 'Base estimator: ': 'Osnovni model: ' + Base estimator:: Osnovni model: n_estimators: false Number of estimators:: Število modelov: learning_rate: false Learning rate:: Hitrost učenja: + loss_index: false + Loss (regression):: Funkcija izgube (za regresijo) + Reproducibility: Ponovljivost random_seed: false Fixed seed for random generator:: Seme generatorja naključnih števil: use_random_seed: false - Boosting method: Metoda pospeševanja (boosting) - algorithm_index: false - Classification algorithm:: Algoritem (za klasifikacijo): - loss_index: false - Regression loss function:: Funkcija izgube (za regresijo): def `set_base_learner`: - 'Base estimator: INVALID': Osnovni model: neveljaven - 'Base estimator: %s': Osnovni model: %s + INVALID: NEVELJAVEN def `get_learner_parameters`: Base estimator: Osnovni model Number of estimators: Število modelov - Algorithm (classification): Algoritem (za klasifikacijo) Loss (regression): Izguba (za regresijo) __main__: false iris: false