-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #169. ### Summary of Changes Added parameter c to SupportVectorMachines --------- Co-authored-by: alex-senger <[email protected]> Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
5adadad
commit a88eb8b
Showing
4 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/safeds/ml/classical/classification/test_support_vector_machine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table, TaggedTable | ||
from safeds.ml.classical.classification import SupportVectorMachine | ||
|
||
|
||
@pytest.fixture() | ||
def training_set() -> TaggedTable: | ||
table = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
return table.tag_columns(target_name="col1", feature_names=["col2"]) | ||
|
||
|
||
class TestC: | ||
def test_should_be_passed_to_fitted_model(self, training_set: TaggedTable) -> None: | ||
fitted_model = SupportVectorMachine(c=2).fit(training_set=training_set) | ||
assert fitted_model._c == 2 | ||
|
||
def test_should_be_passed_to_sklearn(self, training_set: TaggedTable) -> None: | ||
fitted_model = SupportVectorMachine(c=2).fit(training_set) | ||
assert fitted_model._wrapped_classifier is not None | ||
assert fitted_model._wrapped_classifier.C == 2 | ||
|
||
def test_should_raise_if_less_than_or_equal_to_0(self) -> None: | ||
with pytest.raises( | ||
ValueError, | ||
match="The strength of regularization given by the c parameter must be strictly positive.", | ||
): | ||
SupportVectorMachine(c=-1) |
27 changes: 27 additions & 0 deletions
27
tests/safeds/ml/classical/regression/test_support_vector_machine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table, TaggedTable | ||
from safeds.ml.classical.regression import SupportVectorMachine | ||
|
||
|
||
@pytest.fixture() | ||
def training_set() -> TaggedTable: | ||
table = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
return table.tag_columns(target_name="col1", feature_names=["col2"]) | ||
|
||
|
||
class TestC: | ||
def test_should_be_passed_to_fitted_model(self, training_set: TaggedTable) -> None: | ||
fitted_model = SupportVectorMachine(c=2).fit(training_set=training_set) | ||
assert fitted_model._c == 2 | ||
|
||
def test_should_be_passed_to_sklearn(self, training_set: TaggedTable) -> None: | ||
fitted_model = SupportVectorMachine(c=2).fit(training_set) | ||
assert fitted_model._wrapped_regressor is not None | ||
assert fitted_model._wrapped_regressor.C == 2 | ||
|
||
def test_should_raise_if_less_than_or_equal_to_0(self) -> None: | ||
with pytest.raises( | ||
ValueError, | ||
match="The strength of regularization given by the c parameter must be strictly positive.", | ||
): | ||
SupportVectorMachine(c=-1) |