From 9cc421bd27ecf4da8b1802b1e3f5a100baee566a Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Fri, 2 Aug 2024 10:43:12 +0200 Subject: [PATCH] owsvm: degree is an integer --- Orange/widgets/model/owsvm.py | 12 ++++++++++-- Orange/widgets/model/tests/test_owsvm.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Orange/widgets/model/owsvm.py b/Orange/widgets/model/owsvm.py index ae492e77409..5b55d114ca8 100644 --- a/Orange/widgets/model/owsvm.py +++ b/Orange/widgets/model/owsvm.py @@ -35,6 +35,8 @@ class Outputs(OWBaseLearner.Outputs): class Warning(OWBaseLearner.Warning): sparse_data = Msg('Input data is sparse, default preprocessing is to scale it.') + settings_version = 2 + #: Different types of SVMs SVM, Nu_SVM = range(2) #: SVM type @@ -156,8 +158,8 @@ def _add_kernel_box(self): gamma.setSpecialValueText(self._default_gamma) coef0 = gui.doubleSpin( inbox, self, "coef0", 0.0, 10.0, 0.01, label=" c: ", **common) - degree = gui.doubleSpin( - inbox, self, "degree", 0.0, 10.0, 0.5, label=" d: ", **common) + degree = gui.spin( + inbox, self, "degree", 0, 10, 1, label=" d: ", **common) self._kernel_params = [gamma, coef0, degree] gui.rubber(parambox) @@ -255,6 +257,12 @@ def _report_kernel_parameters(self, items): items["Kernel"] = "Sigmoid, tanh({g:.4} x⋅y + {c:.4})".format( g=gamma, c=self.coef0) + @classmethod + def migrate_settings(cls, settings, version): + if version < 2: + if "degree" in settings: + settings["degree"] = int(settings["degree"]) + if __name__ == "__main__": # pragma: no cover WidgetPreview(OWSVM).run(Table("iris")) diff --git a/Orange/widgets/model/tests/test_owsvm.py b/Orange/widgets/model/tests/test_owsvm.py index e6602da30f6..b165e47518b 100644 --- a/Orange/widgets/model/tests/test_owsvm.py +++ b/Orange/widgets/model/tests/test_owsvm.py @@ -102,3 +102,22 @@ def test_sparse_warning(self): data.X = csr_matrix(data.X) self.send_signal(self.widget.Inputs.data, data) self.assertTrue(self.widget.Warning.sparse_data.is_shown()) + + def test_change_degree(self): + data = Table("iris") + self.send_signal(self.widget.Inputs.data, data) + self.widget.kernel_box.buttons[1].click() + degree_spin = self.widget._kernel_params[2] # pylint: disable=protected-access + degree_spin.stepUp() + self.assertEqual(self.widget.degree, 4) + self.click_apply() + self.wait_until_stop_blocking() + self.assertFalse(self.widget.Error.fitting_failed.is_shown()) + + def test_migrate_degree(self): + settings = {} + OWSVM.migrate_settings(settings, 1) + + settings = {"degree": 4.0} + OWSVM.migrate_settings(settings, 1) + self.assertIsInstance(settings["degree"], int)