Skip to content

Commit

Permalink
test: output of predict should include entire input
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Mar 29, 2023
1 parent 9e7b7fe commit a010ec8
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 9 deletions.
5 changes: 5 additions & 0 deletions tests/safeds/ml/classification/test_ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/classification/test_decision_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/classification/test_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
6 changes: 5 additions & 1 deletion tests/safeds/ml/classification/test_k_nearest_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from safeds.data.tabular.containers import Table, TaggedTable, Column
from safeds.exceptions import LearningError, PredictionError
from safeds.ml.classification import Classifier, KNearestNeighbors
from tests.helpers import resolve_resource_path


@pytest.fixture()
Expand Down Expand Up @@ -51,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/classification/test_logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/classification/test_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, classifier: Classifie
prediction = fitted_classifier.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_regressor = classifier.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, classifier: Classifier, valid_data: TaggedTable) -> None:
fitted_classifier = classifier.fit(valid_data)
prediction = fitted_classifier.predict(valid_data.features)
Expand Down
13 changes: 5 additions & 8 deletions tests/safeds/ml/regression/test_ada_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,16 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.target.name == "target"

def test_should_include_other_columns_of_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
other_column_names = list(
set(valid_data.get_column_names()) - set(valid_data.features.get_column_names()) - {valid_data.target.name}
)
assert prediction.keep_only_columns(other_column_names) == valid_data.keep_only_columns(other_column_names)

def test_should_raise_when_not_fitted(self, regressor: Regressor, valid_data: TaggedTable) -> None:
with pytest.raises(PredictionError):
regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_decision_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_elastic_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_k_nearest_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_lasso_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down
5 changes: 5 additions & 0 deletions tests/safeds/ml/regression/test_ridge_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_should_include_features_of_prediction_input(self, regressor: Regressor,
prediction = fitted_regressor.predict(valid_data.features)
assert prediction.features == valid_data.features

def test_should_include_complete_prediction_input(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.drop_columns(["target"]))
assert prediction.drop_columns(["target"]) == valid_data.drop_columns(["target"])

def test_should_set_correct_target_name(self, regressor: Regressor, valid_data: TaggedTable) -> None:
fitted_regressor = regressor.fit(valid_data)
prediction = fitted_regressor.predict(valid_data.features)
Expand Down

0 comments on commit a010ec8

Please sign in to comment.