Skip to content

Commit 6b10a79

Browse files
[FIX] regression also!
1 parent c60d53d commit 6b10a79

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

test/test_pipeline/test_tabular_classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_constant_pipeline_iris(fit_dictionary_tabular):
417417

418418

419419
@pytest.mark.parametrize("fit_dictionary_tabular_dummy", ["classification"], indirect=True)
420-
def test_pipeline_score(self, fit_dictionary_tabular_dummy):
420+
def test_pipeline_score(fit_dictionary_tabular_dummy):
421421
"""This test makes sure that the pipeline is able to achieve a decent score on dummy data
422422
given the default configuration"""
423423
X = fit_dictionary_tabular_dummy['X_train'].copy()

test/test_pipeline/test_tabular_regression.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,6 @@ def test_pipeline_fit(self, fit_dictionary_tabular):
7979
# Make sure a network was fit
8080
assert isinstance(pipeline.named_steps['network'].get_network(), torch.nn.Module)
8181

82-
@pytest.mark.parametrize("fit_dictionary_tabular_dummy", ["regression"], indirect=True)
83-
def test_pipeline_score(self, fit_dictionary_tabular_dummy, fit_dictionary_tabular):
84-
"""This test makes sure that the pipeline is able to achieve a decent score on dummy data
85-
given the default configuration"""
86-
X = fit_dictionary_tabular_dummy['X_train'].copy()
87-
y = fit_dictionary_tabular_dummy['y_train'].copy()
88-
89-
# lower the learning rate of the optimizer until seeding properly works
90-
# with the default learning rate of 0.01 regression sometimes does not converge
91-
pipeline = TabularRegressionPipeline(
92-
dataset_properties=fit_dictionary_tabular_dummy['dataset_properties'],
93-
search_space_updates=HyperparameterSearchSpaceUpdates([
94-
HyperparameterSearchSpaceUpdate("optimizer",
95-
"AdamOptimizer:lr",
96-
value_range=[0.0001, 0.001],
97-
default_value=0.001)
98-
])
99-
)
100-
101-
cs = pipeline.get_hyperparameter_search_space()
102-
config = cs.get_default_configuration()
103-
pipeline.set_hyperparameters(config)
104-
105-
pipeline.fit(fit_dictionary_tabular_dummy)
106-
107-
# we expect the output to have the same batch size as the test input,
108-
# and number of outputs per batch sample equal to the number of targets ("output_shape" in dataset_properties)
109-
expected_output_shape = (X.shape[0],
110-
fit_dictionary_tabular_dummy["dataset_properties"]["output_shape"])
111-
112-
prediction = pipeline.predict(X)
113-
assert isinstance(prediction, np.ndarray)
114-
assert prediction.shape == expected_output_shape
115-
116-
# we should be able to get a decent score on this dummy data
117-
r2_score = metrics.r2(y, prediction)
118-
assert r2_score >= 0.5, f"Pipeline:{pipeline} Config:{config} FitDict: {fit_dictionary_tabular_dummy}"
119-
12082
def test_pipeline_predict(self, fit_dictionary_tabular):
12183
"""This test makes sure that the pipeline is able to predict
12284
given a random configuration"""
@@ -315,3 +277,42 @@ def test_set_range_search_space_updates(self, fit_dictionary_tabular):
315277
# As we are setting num_layers to 1 for fully connected
316278
# head, units_layer does not exist in the configspace
317279
assert 'fully_connected:units_layer' in e.args[0]
280+
281+
282+
@pytest.mark.parametrize("fit_dictionary_tabular_dummy", ["regression"], indirect=True)
283+
def test_pipeline_score(fit_dictionary_tabular_dummy):
284+
"""This test makes sure that the pipeline is able to achieve a decent score on dummy data
285+
given the default configuration"""
286+
X = fit_dictionary_tabular_dummy['X_train'].copy()
287+
y = fit_dictionary_tabular_dummy['y_train'].copy()
288+
289+
# lower the learning rate of the optimizer until seeding properly works
290+
# with the default learning rate of 0.01 regression sometimes does not converge
291+
pipeline = TabularRegressionPipeline(
292+
dataset_properties=fit_dictionary_tabular_dummy['dataset_properties'],
293+
search_space_updates=HyperparameterSearchSpaceUpdates([
294+
HyperparameterSearchSpaceUpdate("optimizer",
295+
"AdamOptimizer:lr",
296+
value_range=[0.0001, 0.001],
297+
default_value=0.001)
298+
])
299+
)
300+
301+
cs = pipeline.get_hyperparameter_search_space()
302+
config = cs.get_default_configuration()
303+
pipeline.set_hyperparameters(config)
304+
305+
pipeline.fit(fit_dictionary_tabular_dummy)
306+
307+
# we expect the output to have the same batch size as the test input,
308+
# and number of outputs per batch sample equal to the number of targets ("output_shape" in dataset_properties)
309+
expected_output_shape = (X.shape[0],
310+
fit_dictionary_tabular_dummy["dataset_properties"]["output_shape"])
311+
312+
prediction = pipeline.predict(X)
313+
assert isinstance(prediction, np.ndarray)
314+
assert prediction.shape == expected_output_shape
315+
316+
# we should be able to get a decent score on this dummy data
317+
r2_score = metrics.r2(y, prediction)
318+
assert r2_score >= 0.5, f"Pipeline:{pipeline} Config:{config} FitDict: {fit_dictionary_tabular_dummy}"

0 commit comments

Comments
 (0)