From baeb6e3c811c7e97ca222a1ce370bccf0136fb81 Mon Sep 17 00:00:00 2001 From: Felix Wick Date: Thu, 21 Dec 2023 16:33:47 +0100 Subject: [PATCH] test renaming --- tests/test_integration.py | 74 +++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index cccd9c5..ec39c4e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -29,25 +29,8 @@ np.random.seed(42) -def test_interactions_selection(prepare_data, feature_properties, features, is_plot): - X, y = prepare_data - - X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) - - best_interaction_term_features = select_interaction_terms_anova(X_train, y_train, feature_properties, 3, 5) - - expected = [ - ("PG_ID_3", "L_ID"), - ("PG_ID_3", "PROMOTION_TYPE"), - ("L_ID", "PROMOTION_TYPE"), - ("PG_ID_3", "L_ID", "dayofweek"), - ("PG_ID_3", "L_ID", "PROMOTION_TYPE"), - ] - assert best_interaction_term_features == expected - - features_ext = features.copy() - features_ext += best_interaction_term_features - +@pytest.fixture(scope="function") +def cb_poisson_regressor_model(features, feature_properties): explicit_smoothers = { ("dayofyear",): SeasonalSmoother(order=3), ("price_ratio",): IsotonicRegressor(increasing=False), @@ -58,15 +41,25 @@ def test_interactions_selection(prepare_data, feature_properties, features, is_p observers.PlottingObserver(iteration=-1), ] - CB_est = pipeline_CBPoissonRegressor( + CB_pipeline = pipeline_CBPoissonRegressor( feature_properties=feature_properties, - feature_groups=features_ext, + feature_groups=features, observers=plobs, maximal_iterations=50, smoother_choice=common_smoothers.SmootherChoiceGroupBy( use_regression_type=True, use_normalization=False, explicit_smoothers=explicit_smoothers ), ) + + return CB_pipeline + + +def test_poisson_regression(is_plot, prepare_data, cb_poisson_regressor_model): + X, y = prepare_data + + X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) + + CB_est = cb_poisson_regressor_model CB_est.fit(X_train, y_train) if is_plot: @@ -76,11 +69,28 @@ def test_interactions_selection(prepare_data, feature_properties, features, is_p yhat = CB_est.predict(X_test) mad = np.nanmean(np.abs(y_test - yhat)) - np.testing.assert_almost_equal(mad, 1.641, 3) + np.testing.assert_almost_equal(mad, 1.688, 3) -@pytest.fixture(scope="function") -def cb_poisson_regressor_model(features, feature_properties): +def test_poisson_regression_interactions_selection(prepare_data, feature_properties, features, is_plot): + X, y = prepare_data + + X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) + + best_interaction_term_features = select_interaction_terms_anova(X_train, y_train, feature_properties, 3, 5) + + expected = [ + ("PG_ID_3", "L_ID"), + ("PG_ID_3", "PROMOTION_TYPE"), + ("L_ID", "PROMOTION_TYPE"), + ("PG_ID_3", "L_ID", "dayofweek"), + ("PG_ID_3", "L_ID", "PROMOTION_TYPE"), + ] + assert best_interaction_term_features == expected + + features_ext = features.copy() + features_ext += best_interaction_term_features + explicit_smoothers = { ("dayofyear",): SeasonalSmoother(order=3), ("price_ratio",): IsotonicRegressor(increasing=False), @@ -91,25 +101,15 @@ def cb_poisson_regressor_model(features, feature_properties): observers.PlottingObserver(iteration=-1), ] - CB_pipeline = pipeline_CBPoissonRegressor( + CB_est = pipeline_CBPoissonRegressor( feature_properties=feature_properties, - feature_groups=features, + feature_groups=features_ext, observers=plobs, maximal_iterations=50, smoother_choice=common_smoothers.SmootherChoiceGroupBy( use_regression_type=True, use_normalization=False, explicit_smoothers=explicit_smoothers ), ) - - return CB_pipeline - - -def test_poisson_regression(is_plot, prepare_data, cb_poisson_regressor_model): - X, y = prepare_data - - X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) - - CB_est = cb_poisson_regressor_model CB_est.fit(X_train, y_train) if is_plot: @@ -119,7 +119,7 @@ def test_poisson_regression(is_plot, prepare_data, cb_poisson_regressor_model): yhat = CB_est.predict(X_test) mad = np.nanmean(np.abs(y_test - yhat)) - np.testing.assert_almost_equal(mad, 1.688, 3) + np.testing.assert_almost_equal(mad, 1.641, 3) @pytest.fixture(scope="function")