Skip to content

Commit

Permalink
Ada Boost: Remove option 'algorithm' from the widget
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Oct 10, 2024
1 parent f46cc7f commit aa5b946
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 44 deletions.
50 changes: 22 additions & 28 deletions Orange/widgets/model/owadaboost.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()))

Expand Down
3 changes: 0 additions & 3 deletions Orange/widgets/model/tests/test_owadaboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 5 additions & 13 deletions i18n/si/msgs.jaml
Original file line number Diff line number Diff line change
Expand Up @@ -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__`:
Expand Down Expand Up @@ -9510,35 +9509,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
Expand Down

0 comments on commit aa5b946

Please sign in to comment.