Skip to content

Commit

Permalink
small update
Browse files Browse the repository at this point in the history
  • Loading branch information
sibre28 committed Aug 19, 2024
1 parent 69aa8e6 commit 7f23c69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/safeds/ml/nn/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ def _get_best_cnn_model_table(
#Set positive class to index of positive column, to be able to calculate Classification Metrics
if positive_class is not None:
for column_index in range(labels.column_count):
if labels.column_names[column_index] == positive_class:
#TODO Find out if a column is the positive class, maybe by the column name?
#if labels.column_names[column_index] == positive_class:
positive_class = labels.column_names[column_index]
break

Expand Down
26 changes: 26 additions & 0 deletions tests/safeds/ml/nn/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ def test_should_catch_invalid_fit_data(self, device: Device, table: TabularDatas
):
model.fit(table)

def test_should_raise_when_time_series_classification_with_continuous_data(self, device: Device) -> None:
configure_test_with_device(device)
data = Table.from_dict({"a": [1, 2, 3], "b": [1, 2, 3], "c": [0, 1, 0]}).to_time_series_dataset("c",1,continuous=True)
model = NeuralNetworkClassifier(
InputConversionTimeSeries(),
[ForwardLayer(neuron_count=4), LSTMLayer(neuron_count=1)],
)
with pytest.raises(
NotImplementedError,
match="Continuous Predictions are currently not supported for Time Series Classification."
):
model.fit(data)

def test_should_raise_if_fit_doesnt_batch_callback(self, device: Device) -> None:
configure_test_with_device(device)
model = NeuralNetworkClassifier(
Expand Down Expand Up @@ -312,6 +325,19 @@ def test_should_raise_when_fitting_by_exhaustive_search_without_choice(self, dev
"accuracy",
)

def test_should_raise_when_time_series_classification_with_continuous_data(self, device: Device) -> None:
configure_test_with_device(device)
data = Table.from_dict({"a": [1, 2, 3], "b": [1, 2, 3], "c": [0, 1, 0]}).to_time_series_dataset("c",1,continuous=True)
model = NeuralNetworkClassifier(
InputConversionTimeSeries(),
[ForwardLayer(neuron_count=Choice(2, 4)), LSTMLayer(neuron_count=1)],
)
with pytest.raises(
NotImplementedError,
match="Continuous Predictions are currently not supported for Time Series Classification."
):
model.fit_by_exhaustive_search(data, "accuracy")

@pytest.mark.parametrize(
("metric", "positive_class"),
[
Expand Down

0 comments on commit 7f23c69

Please sign in to comment.