Skip to content

Commit

Permalink
owsvm: degree is an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Aug 2, 2024
1 parent 09df730 commit ec73c5e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 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"))
1 change: 0 additions & 1 deletion Orange/widgets/model/tests/test_owgradientboosting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import unittest
import sys
from typing import Type
Expand Down
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]
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 ec73c5e

Please sign in to comment.