Skip to content

Commit

Permalink
Merge pull request #6866 from markotoplak/fix-svm-degree
Browse files Browse the repository at this point in the history
[FIX] SVM: degree has to be an integer
  • Loading branch information
janezd authored Aug 23, 2024
2 parents 09df730 + 9cc421b commit 02a0652
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Orange/widgets/model/owsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"))
19 changes: 19 additions & 0 deletions Orange/widgets/model/tests/test_owsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 02a0652

Please sign in to comment.