Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fix broken DynamicFactor._predict_interval #4479

Merged
merged 6 commits into from Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 9 additions & 13 deletions sktime/forecasting/dynamic_factor.py
Expand Up @@ -268,23 +268,23 @@ def _predict_interval(self, fh, X=None, coverage: [float] = None):
# statsmodels requires zero-based indexing starting at the
# beginning of the training series when passing integers
start, end = fh.to_absolute_int(self._y.index[0], self.cutoff)[[0, -1]]
steps = end - len(self._y) + 1
ix = fh.to_indexer()

model = self._fitted_forecaster

df_list = []
# generate the forecasts for each alpha/coverage
for coverage in coverage_list:

alpha = -0.5 * coverage + 0.5
alpha = 1 - coverage

if "exog" in inspect.signature(model.__init__).parameters.keys():
y_pred = model.get_forecast(steps=(end - start) + 1, exog=X).conf_int(
alpha=alpha
)
y_pred = model.get_forecast(steps=steps, exog=X).conf_int(alpha=alpha)
else:
y_pred = model.get_forecast(steps=(end - start) + 1).conf_int(
alpha=alpha
)
y_pred = model.get_forecast(steps=steps).conf_int(alpha=alpha)

y_pred = y_pred.iloc[ix]

y_pred.rename(
columns={orig_col: orig_col + f" {coverage}" for orig_col in y_pred},
Expand Down Expand Up @@ -332,11 +332,7 @@ def _predict_interval(self, fh, X=None, coverage: [float] = None):
predictions_df_2.values, columns=pd.MultiIndex.from_tuples(final_columns)
)

if "int" in (self._y.index[0]).__class__.__name__: # Rather fishy solution
predictions_df_3.index = np.arange(
start + self._y.index[0], end + self._y.index[0] + 1
)
return predictions_df_3.loc[fh.to_absolute(self.cutoff).to_pandas()]
predictions_df_3.index = fh.to_absolute(self.cutoff).to_pandas()

return predictions_df_3

Expand Down Expand Up @@ -556,6 +552,6 @@ def get_test_params(cls, parameter_set="default"):
`create_test_instance` uses the first (or only) dictionary in `params
"""
params1 = {"k_factors": 1, "factor_order": 1}
params2 = {"enforce_stationarity": False, "maxiter": 25, "low_memory": True}
params2 = {"maxiter": 25, "low_memory": True}

return [params1, params2]
6 changes: 0 additions & 6 deletions sktime/tests/_config.py
Expand Up @@ -130,12 +130,6 @@
# SAX returns strange output format
# this needs to be fixed, was not tested previously due to legacy exception
"SAX": "test_fit_transform_output",
# known bug in DynamicFactor, returns wrong index, #4362
"DynamicFactor": [
"test_predict_interval",
"test_predict_quantiles",
"test_predict_proba",
],
}

# We use estimator tags in addition to class hierarchies to further distinguish
Expand Down