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

feat: hyperparameter optimization for fnn models #897

Merged
merged 42 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a7575de
Add fit_by_exhaustive_search to NNClassifier
sibre28 Jul 11, 2024
2ac1169
Add fit_by_exhaustive_search to NNRegressor
sibre28 Jul 11, 2024
79a887b
Add Classifier and Regressor Metric
sibre28 Jul 11, 2024
a5c3713
add FittingWithChoiceError and FittingWithoutChoiceError
sibre28 Jul 11, 2024
a3b9593
Add choices to layers
sibre28 Jul 11, 2024
41dd053
linter fixes
sibre28 Jul 11, 2024
b542fd6
linter fixes
sibre28 Jul 11, 2024
8b7a2cf
linter fixes
sibre28 Jul 11, 2024
b718f74
linter fixes
sibre28 Jul 11, 2024
04c3ac7
style: apply automated linter fixes
megalinter-bot Jul 11, 2024
3a817ce
added tests fir invalid outputsizes in choices
sibre28 Jul 11, 2024
ed40030
Merge remote-tracking branch 'origin/861-hyperparameter-optimization-…
sibre28 Jul 11, 2024
07572fc
add __eq__ to choice
sibre28 Jul 12, 2024
5f13bfa
add gru_layer tests
sibre28 Jul 12, 2024
2dc29f2
update choice to remove duplicates and raise EmptyChoiceError when empty
sibre28 Jul 12, 2024
d018cf2
forgot to import whoops
sibre28 Jul 12, 2024
87224ee
add choice tests
sibre28 Jul 12, 2024
1c3da1c
add lstm layer tests
sibre28 Jul 12, 2024
00a36fe
add tests
sibre28 Jul 12, 2024
4601b0a
add tests
sibre28 Jul 12, 2024
60ef221
Merge branch 'main' into 861-hyperparameter-optimization-for-nn-models-1
sibre28 Jul 12, 2024
4b8d3f6
linter fix
sibre28 Jul 12, 2024
3cd1a99
Merge remote-tracking branch 'origin/861-hyperparameter-optimization-…
sibre28 Jul 12, 2024
fa141e8
linter fix
sibre28 Jul 12, 2024
87549b7
add tests for fit_by_exhaustive_search and restructure model tests
sibre28 Jul 13, 2024
af9e9f7
linter fix
sibre28 Jul 13, 2024
bf4802c
style: apply automated linter fixes
megalinter-bot Jul 13, 2024
da408be
style: apply automated linter fixes
megalinter-bot Jul 13, 2024
7abb1e9
set context of processpoolexecutor
sibre28 Jul 13, 2024
0e6e53a
add tests for all metrics
sibre28 Jul 13, 2024
5f51cd7
linter fix
sibre28 Jul 13, 2024
02c0f05
codecov
sibre28 Jul 13, 2024
7ff98d2
add missing image test, dont know why it went missing
sibre28 Jul 13, 2024
84033cf
style: apply automated linter fixes
megalinter-bot Jul 13, 2024
3d0415e
style: apply automated linter fixes
megalinter-bot Jul 13, 2024
083c385
Merge branch 'main' into 861-hyperparameter-optimization-for-nn-models-1
sibre28 Jul 14, 2024
3985dfb
add docs for fit_by_exhaustive_search
sibre28 Jul 15, 2024
6dcd34f
change Metric Enums to Literals
sibre28 Jul 15, 2024
d00c673
Delete Metric Enums
sibre28 Jul 15, 2024
99b258f
remove imports of deleted enums
sibre28 Jul 15, 2024
1048d2c
style: apply automated linter fixes
megalinter-bot Jul 15, 2024
7903fad
style: apply automated linter fixes
megalinter-bot Jul 15, 2024
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
8 changes: 7 additions & 1 deletion src/safeds/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from ._ml import (
DatasetMissesDataError,
DatasetMissesFeaturesError,
EmptyChoiceError,
FeatureDataMismatchError,
FittingWithChoiceError,
FittingWithoutChoiceError,
InputSizeError,
InvalidFitDataError,
InvalidModelStructureError,
Expand Down Expand Up @@ -72,13 +75,16 @@ class OutOfBoundsError(SafeDsError):
# ML exceptions
"DatasetMissesDataError",
"DatasetMissesFeaturesError",
"TargetDataMismatchError",
"EmptyChoiceError",
"FeatureDataMismatchError",
"FittingWithChoiceError",
"FittingWithoutChoiceError",
"InvalidFitDataError",
"InputSizeError",
"InvalidModelStructureError",
"LearningError",
"ModelNotFittedError",
"PlainTableError",
"PredictionError",
"TargetDataMismatchError",
]
27 changes: 27 additions & 0 deletions src/safeds/exceptions/_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ def __init__(self) -> None:
super().__init__("Dataset contains no rows")


class EmptyChoiceError(ValueError):
"""Raised when a choice object is created, but no arguments are provided."""

def __init__(self) -> None:
super().__init__("Please provide at least one Value in a Choice Parameter")


class FittingWithChoiceError(Exception):
"""Raised when a model is fitted with a choice object as a parameter."""

def __init__(self) -> None:
super().__init__(
"Error occurred while fitting: Trying to fit with a Choice Parameter. Please use "
"fit_by_exhaustive_search() instead.",
)


class FittingWithoutChoiceError(Exception):
"""Raised when a model is fitted by exhaustive search without a choice object as a parameter."""

def __init__(self) -> None:
super().__init__(
"Error occurred while fitting: Trying to fit by exhaustive search without a Choice "
"Parameter. Please use fit() instead.",
)


class InvalidFitDataError(Exception):
"""Raised when a Neural Network is fitted on invalid data."""

Expand Down
14 changes: 13 additions & 1 deletion src/safeds/ml/hyperparameters/_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from collections.abc import Collection
from typing import TYPE_CHECKING, TypeVar

from safeds.exceptions import EmptyChoiceError

if TYPE_CHECKING:
from collections.abc import Iterator
from typing import Any
Expand All @@ -15,14 +17,17 @@ class Choice(Collection[T]):

def __init__(self, *args: T) -> None:
"""
Create a new choice.
Create a new choice. Duplicate values will be removed.

Parameters
----------
*args:
The values to choose from.
"""
self.elements = list(args)
if len(args) < 1:
raise EmptyChoiceError
self.elements = list(dict.fromkeys(args))

def __contains__(self, value: Any) -> bool:
"""
Expand Down Expand Up @@ -61,3 +66,10 @@ def __len__(self) -> int:
The number of values in this choice.
"""
return len(self.elements)

def __eq__(self, other: object) -> bool:
if not isinstance(other, Choice):
return NotImplemented
if self is other:
return True
return (self is other) or (self.elements == other.elements)
Loading