Skip to content

Commit

Permalink
test renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixWick committed Dec 21, 2023
1 parent fe809bc commit baeb6e3
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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:
Expand All @@ -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),
Expand All @@ -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:
Expand All @@ -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")
Expand Down

0 comments on commit baeb6e3

Please sign in to comment.