Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherbunn committed Aug 11, 2023
1 parent c435cd1 commit dd72b1b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,18 @@ def get_prediction_intervals(
predictions (pd.Series): Not used for VARMAX regressor.
Returns:
dict: Prediction intervals, keys are in the format {coverage}_lower or {coverage}_upper.
dict[dict]: A dict of prediction intervals, where the dict is in the format {series_id: {coverage}_lower or {coverage}_upper}.
"""
if coverage is None:
coverage = [0.95]

Check warning on line 221 in evalml/pipelines/components/estimators/regressors/varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/pipelines/components/estimators/regressors/varmax_regressor.py#L220-L221

Added lines #L220 - L221 were not covered by tests

X, y = self._manage_woodwork(X, y)
if self.use_covariates:
use_exog = (

Check warning on line 224 in evalml/pipelines/components/estimators/regressors/varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/pipelines/components/estimators/regressors/varmax_regressor.py#L223-L224

Added lines #L223 - L224 were not covered by tests
# If exogenous variables were used during training
self._component_obj._fitted_forecaster.model.exog is not None
and self.use_covariates
)
if use_exog:
X = X.ww.select(exclude=["Datetime"])
X = convert_bool_to_double(X)

Check warning on line 231 in evalml/pipelines/components/estimators/regressors/varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/pipelines/components/estimators/regressors/varmax_regressor.py#L229-L231

Added lines #L229 - L231 were not covered by tests
# Accesses the fitted statsmodels model within sktime
Expand All @@ -233,9 +238,10 @@ def get_prediction_intervals(
repetitions=400,
anchor="end",
random_state=self.random_seed,
exog=X if self.use_covariates else None,
exog=X if use_exog else None,
)
prediction_interval_result = {}

Check warning on line 243 in evalml/pipelines/components/estimators/regressors/varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/pipelines/components/estimators/regressors/varmax_regressor.py#L243

Added line #L243 was not covered by tests
# Access the target column names (i.e. the series_id values) that the VARMAX component obj was fitted on
for series in self._component_obj._fitted_forecaster.model.endog_names:
series_result = {}
series_preds = y_pred[[col for col in y_pred.columns if series in col]]
Expand Down
38 changes: 20 additions & 18 deletions evalml/tests/component_tests/test_varmax_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,29 @@ def test_varmax_regressor_can_forecast_arbitrary_dates_past_holdout(
varmax.predict(X_test)


@pytest.mark.parametrize("use_X_train", [True, False])
@pytest.mark.parametrize("coverages", [None, [0.85], [0.95, 0.90, 0.85]])
@pytest.mark.parametrize("use_covariates", [True, False])
def test_varmax_regressor_prediction_intervals(use_covariates, ts_multiseries_data):
def test_varmax_regressor_prediction_intervals(

Check warning on line 321 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L318-L321

Added lines #L318 - L321 were not covered by tests
use_covariates,
coverages,
use_X_train,
ts_multiseries_data,
):
X_train, X_test, y_train = ts_multiseries_data(no_features=not use_covariates)

Check warning on line 327 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L327

Added line #L327 was not covered by tests

clf = VARMAXRegressor(use_covariates=use_covariates)
clf.fit(X=X_train if use_X_train else None, y=y_train)

Check warning on line 330 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L329-L330

Added lines #L329 - L330 were not covered by tests

clf.fit(X_train, y_train)
result_95 = clf.get_prediction_intervals(X_test)

series_id_targets = list(result_95.keys())
for series in series_id_targets:
series_result_95 = result_95[series]
conf_ints = list(series_result_95.keys())
data = list(series_result_95.values())

assert len(conf_ints) == 2
assert len(data) == 2
assert conf_ints[0] == "0.95_lower"
assert conf_ints[1] == "0.95_upper"
# Check we are not using exogenous variables if use_covariates=False, even if X_test is passed.
if not use_covariates or not use_X_train:
with patch.object(

Check warning on line 334 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L333-L334

Added lines #L333 - L334 were not covered by tests
clf._component_obj._fitted_forecaster,
"simulate",
) as mock_simulate:
clf.get_prediction_intervals(X_test, None, coverages)
assert mock_simulate.call_args[1]["exog"] is None

Check warning on line 339 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L338-L339

Added lines #L338 - L339 were not covered by tests

coverages = [0.95, 0.90, 0.85]
results_coverage = clf.get_prediction_intervals(X_test, None, coverages)
predictions = clf.predict(X_test)

Check warning on line 342 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L341-L342

Added lines #L341 - L342 were not covered by tests

Expand All @@ -345,10 +347,10 @@ def test_varmax_regressor_prediction_intervals(use_covariates, ts_multiseries_da
conf_ints = list(series_results_coverage.keys())
data = list(series_results_coverage.values())

Check warning on line 348 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L344-L348

Added lines #L344 - L348 were not covered by tests

assert len(conf_ints) == 6
assert len(data) == 6
assert len(conf_ints) == (len(coverages) if coverages is not None else 1) * 2
assert len(data) == (len(coverages) if coverages is not None else 1) * 2

Check warning on line 351 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L350-L351

Added lines #L350 - L351 were not covered by tests

for interval in coverages:
for interval in coverages if coverages is not None else [0.95]:
conf_int_lower = f"{interval}_lower"
conf_int_upper = f"{interval}_upper"

Check warning on line 355 in evalml/tests/component_tests/test_varmax_regressor.py

View check run for this annotation

Codecov / codecov/patch

evalml/tests/component_tests/test_varmax_regressor.py#L353-L355

Added lines #L353 - L355 were not covered by tests

Expand Down

0 comments on commit dd72b1b

Please sign in to comment.