-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Added parameter c to SupportVectorMachines
#267
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
Merged
lars-reimann
merged 6 commits into
main
from
169-set-c-parameter-for-regularization-of-a-supportvectormachine
May 5, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7842a2b
feat: Added parameter c to SupportVectorMachines
Marsmaennchen221 6e9c6b5
style: apply automated linter fixes
megalinter-bot 1c198ee
fix: Apply suggestions from code review
alex-senger eb43f7c
style: apply automated linter fixes
megalinter-bot 7017360
style: apply automated linter fixes
megalinter-bot 9f9ba6f
Merge branch 'main' into 169-set-c-parameter-for-regularization-of-a-…
lars-reimann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.