Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] SVM: degree has to be an integer #6866

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading