From e8286f2fed3549cb22bf2be8ee122002fb50c6ff Mon Sep 17 00:00:00 2001 From: "sandi.mikus@gmail.com" Date: Wed, 21 Feb 2018 13:28:33 +0100 Subject: [PATCH 1/6] Deprecation fix: changed n_iter to max_iter (SGDClassifier) --- Orange/classification/sgd.py | 8 ++++---- Orange/widgets/model/owsgd.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Orange/classification/sgd.py b/Orange/classification/sgd.py index 0dce4d34b5e..32bc326371e 100644 --- a/Orange/classification/sgd.py +++ b/Orange/classification/sgd.py @@ -14,9 +14,9 @@ class SGDClassificationLearner(SklLearner): preprocessors = SklLearner.preprocessors + [Normalize()] def __init__(self, loss='hinge', penalty='l2', alpha=0.0001, - l1_ratio=0.15,fit_intercept=True, n_iter=5, shuffle=True, - epsilon=0.1, random_state=None, learning_rate='invscaling', - eta0=0.01, power_t=0.25, warm_start=False, average=False, - preprocessors=None): + l1_ratio=0.15,fit_intercept=True, max_iter=5, + tol=None, shuffle=True, epsilon=0.1, random_state=None, + learning_rate='invscaling', eta0=0.01, power_t=0.25, + warm_start=False, average=False, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() diff --git a/Orange/widgets/model/owsgd.py b/Orange/widgets/model/owsgd.py index 0f40ee8fbfa..c9c1f82d82c 100644 --- a/Orange/widgets/model/owsgd.py +++ b/Orange/widgets/model/owsgd.py @@ -76,7 +76,7 @@ class Outputs(OWBaseLearner.Outputs): learning_rate_index = Setting(0) eta0 = Setting(.01) power_t = Setting(.25) - n_iter = Setting(5) + max_iter = Setting(10) def add_main_layout(self): self._add_algorithm_to_layout() @@ -150,8 +150,8 @@ def _add_learning_params_to_layout(self): callback=self.settings_changed) gui.separator(box, height=12) - self.n_iter_spin = gui.spin( - box, self, 'n_iter', 1, MAXINT - 1, label='Number of iterations: ', + self.max_iter_spin = gui.spin( + box, self, 'max_iter', 1, MAXINT - 1, label='Number of iterations: ', controlWidth=80, alignment=Qt.AlignRight, callback=self.settings_changed) # Wrap shuffle_cbx inside another hbox to align it with the random_seed @@ -246,7 +246,7 @@ def create_learner(self): learning_rate=self.learning_rates[self.learning_rate_index][1], eta0=self.eta0, power_t=self.power_t, - n_iter=self.n_iter, + max_iter=self.max_iter, preprocessors=self.preprocessors, **params) From e3940c0543d3f8327cbeb7f7a690436e75dddc9b Mon Sep 17 00:00:00 2001 From: "sandi.mikus@gmail.com" Date: Wed, 21 Feb 2018 13:46:54 +0100 Subject: [PATCH 2/6] Linting: removed trailing whitespace --- Orange/classification/sgd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Orange/classification/sgd.py b/Orange/classification/sgd.py index 32bc326371e..50e2a8d5773 100644 --- a/Orange/classification/sgd.py +++ b/Orange/classification/sgd.py @@ -14,9 +14,9 @@ class SGDClassificationLearner(SklLearner): preprocessors = SklLearner.preprocessors + [Normalize()] def __init__(self, loss='hinge', penalty='l2', alpha=0.0001, - l1_ratio=0.15,fit_intercept=True, max_iter=5, - tol=None, shuffle=True, epsilon=0.1, random_state=None, - learning_rate='invscaling', eta0=0.01, power_t=0.25, + l1_ratio=0.15,fit_intercept=True, max_iter=5, + tol=None, shuffle=True, epsilon=0.1, random_state=None, + learning_rate='invscaling', eta0=0.01, power_t=0.25, warm_start=False, average=False, preprocessors=None): super().__init__(preprocessors=preprocessors) self.params = vars() From 297835c0b1fa24c8b88a5204dc53982bd82aa752 Mon Sep 17 00:00:00 2001 From: "sandi.mikus@gmail.com" Date: Wed, 21 Feb 2018 16:47:30 +0100 Subject: [PATCH 3/6] Migrate_settings: max_iter compatibility for older OWSGD --- Orange/widgets/model/owsgd.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Orange/widgets/model/owsgd.py b/Orange/widgets/model/owsgd.py index c9c1f82d82c..80799994591 100644 --- a/Orange/widgets/model/owsgd.py +++ b/Orange/widgets/model/owsgd.py @@ -306,6 +306,11 @@ def update_model(self): coeffs.name = "coefficients" self.Outputs.coefficients.send(coeffs) + @classmethod + def migrate_settings(cls, settings_, version): + if version < 2: + settings_["max_iter"] = settings_.pop("n_iter", 5) + if __name__ == '__main__': import sys From 60c741f5c4d55bfef5bf93b3bea5977296f23182 Mon Sep 17 00:00:00 2001 From: "sandi.mikus@gmail.com" Date: Wed, 21 Feb 2018 16:51:57 +0100 Subject: [PATCH 4/6] Changed default max_iter in SGDClassifier back to 5 (same as sklearn) --- Orange/widgets/model/owsgd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Orange/widgets/model/owsgd.py b/Orange/widgets/model/owsgd.py index 80799994591..f34111e32a7 100644 --- a/Orange/widgets/model/owsgd.py +++ b/Orange/widgets/model/owsgd.py @@ -76,7 +76,7 @@ class Outputs(OWBaseLearner.Outputs): learning_rate_index = Setting(0) eta0 = Setting(.01) power_t = Setting(.25) - max_iter = Setting(10) + max_iter = Setting(5) def add_main_layout(self): self._add_algorithm_to_layout() From 936cf1f51c4c8a388d7b8a7df5e2fef56c03fd26 Mon Sep 17 00:00:00 2001 From: "sandi.mikus@gmail.com" Date: Thu, 22 Feb 2018 15:08:46 +0100 Subject: [PATCH 5/6] Modified SGD widget, SGDClassifier and SGDRegressionLearner to comply with sklearn 0.21 changes (tol and max_iter) --- Orange/classification/sgd.py | 2 +- Orange/regression/linear.py | 4 ++-- Orange/widgets/model/owsgd.py | 18 +++++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Orange/classification/sgd.py b/Orange/classification/sgd.py index 50e2a8d5773..84739bf0eeb 100644 --- a/Orange/classification/sgd.py +++ b/Orange/classification/sgd.py @@ -14,7 +14,7 @@ class SGDClassificationLearner(SklLearner): preprocessors = SklLearner.preprocessors + [Normalize()] def __init__(self, loss='hinge', penalty='l2', alpha=0.0001, - l1_ratio=0.15,fit_intercept=True, max_iter=5, + l1_ratio=0.15, fit_intercept=True, max_iter=5, tol=None, shuffle=True, epsilon=0.1, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, warm_start=False, average=False, preprocessors=None): diff --git a/Orange/regression/linear.py b/Orange/regression/linear.py index 0186483ee0b..549782ce3d8 100644 --- a/Orange/regression/linear.py +++ b/Orange/regression/linear.py @@ -84,8 +84,8 @@ class SGDRegressionLearner(LinearRegressionLearner): preprocessors = SklLearner.preprocessors + [Normalize()] def __init__(self, loss='squared_loss', penalty='l2', alpha=0.0001, - l1_ratio=0.15, fit_intercept=True, n_iter=5, shuffle=True, - epsilon=0.1, n_jobs=1, random_state=None, + l1_ratio=0.15, fit_intercept=True, max_iter=5, tol=None, + shuffle=True, epsilon=0.1, n_jobs=1, random_state=None, learning_rate='invscaling', eta0=0.01, power_t=0.25, class_weight=None, warm_start=False, average=False, preprocessors=None): diff --git a/Orange/widgets/model/owsgd.py b/Orange/widgets/model/owsgd.py index f34111e32a7..c1e9b4021aa 100644 --- a/Orange/widgets/model/owsgd.py +++ b/Orange/widgets/model/owsgd.py @@ -76,7 +76,8 @@ class Outputs(OWBaseLearner.Outputs): learning_rate_index = Setting(0) eta0 = Setting(.01) power_t = Setting(.25) - max_iter = Setting(5) + max_iter = Setting(1000) + tol = Setting(1e-3) def add_main_layout(self): self._add_algorithm_to_layout() @@ -154,6 +155,13 @@ def _add_learning_params_to_layout(self): box, self, 'max_iter', 1, MAXINT - 1, label='Number of iterations: ', controlWidth=80, alignment=Qt.AlignRight, callback=self.settings_changed) + + self.tol_spin = gui.spin( + box, self, 'tol', 0, 10., .1e-3, spinType=float, controlWidth=80, + label='Tolerance (stopping criterion): ', alignment=Qt.AlignRight, + callback=self.settings_changed) + gui.separator(box, height=12) + # Wrap shuffle_cbx inside another hbox to align it with the random_seed # spin box on OSX self.shuffle_cbx = gui.checkBox( @@ -247,6 +255,7 @@ def create_learner(self): eta0=self.eta0, power_t=self.power_t, max_iter=self.max_iter, + tol=self.tol, preprocessors=self.preprocessors, **params) @@ -306,11 +315,6 @@ def update_model(self): coeffs.name = "coefficients" self.Outputs.coefficients.send(coeffs) - @classmethod - def migrate_settings(cls, settings_, version): - if version < 2: - settings_["max_iter"] = settings_.pop("n_iter", 5) - if __name__ == '__main__': import sys @@ -324,4 +328,4 @@ def migrate_settings(cls, settings_, version): ow.set_data(d) ow.show() a.exec_() - ow.saveSettings() + ow.saveSettings() \ No newline at end of file From 9d208e87eb82153cd38d26494c6c9dfdd9489c83 Mon Sep 17 00:00:00 2001 From: Lan Zagar Date: Fri, 23 Feb 2018 10:03:00 +0100 Subject: [PATCH 6/6] owsgd: Allow tol toggling + migrate settings --- Orange/widgets/model/owsgd.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Orange/widgets/model/owsgd.py b/Orange/widgets/model/owsgd.py index c1e9b4021aa..14ddffeaa8a 100644 --- a/Orange/widgets/model/owsgd.py +++ b/Orange/widgets/model/owsgd.py @@ -24,6 +24,8 @@ class OWSGD(OWBaseLearner): ] priority = 90 + settings_version = 2 + LEARNER = SGDLearner class Outputs(OWBaseLearner.Outputs): @@ -78,6 +80,7 @@ class Outputs(OWBaseLearner.Outputs): power_t = Setting(.25) max_iter = Setting(1000) tol = Setting(1e-3) + tol_enabled = Setting(True) def add_main_layout(self): self._add_algorithm_to_layout() @@ -158,8 +161,8 @@ def _add_learning_params_to_layout(self): self.tol_spin = gui.spin( box, self, 'tol', 0, 10., .1e-3, spinType=float, controlWidth=80, - label='Tolerance (stopping criterion): ', alignment=Qt.AlignRight, - callback=self.settings_changed) + label='Tolerance (stopping criterion): ', checked='tol_enabled', + alignment=Qt.AlignRight, callback=self.settings_changed) gui.separator(box, height=12) # Wrap shuffle_cbx inside another hbox to align it with the random_seed @@ -255,7 +258,7 @@ def create_learner(self): eta0=self.eta0, power_t=self.power_t, max_iter=self.max_iter, - tol=self.tol, + tol=self.tol if self.tol_enabled else None, preprocessors=self.preprocessors, **params) @@ -315,6 +318,12 @@ def update_model(self): coeffs.name = "coefficients" self.Outputs.coefficients.send(coeffs) + @classmethod + def migrate_settings(cls, settings_, version): + if version < 2: + settings_["max_iter"] = settings_.pop("n_iter", 5) + settings_["tol_enabled"] = False + if __name__ == '__main__': import sys @@ -328,4 +337,4 @@ def update_model(self): ow.set_data(d) ow.show() a.exec_() - ow.saveSettings() \ No newline at end of file + ow.saveSettings()