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] KeyError when using custom root name #79

Open
aakashparsi opened this issue Jun 14, 2021 · 2 comments
Open

[BUG] KeyError when using custom root name #79

aakashparsi opened this issue Jun 14, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@aakashparsi
Copy link
Collaborator

Describe the bug
When I'm using a custom root name rather than total, I've got KeyError: total from the forecast_proportions method.

To Reproduce

hts.HTSRegressor(model = 'auto_arima', revision_method = 'FP', n_jobs = 0)
htsmodel.fit(trainSet, hierarchy, root = 'TotalWeight')
htsfit.predict(steps_ahead = forecast_horizon)

Error Trace

KeyError Traceback (most recent call last)
in
----> 1 pred = htsfit.predict(steps_ahead = forecast_horizon)

~/.local/lib/python3.6/site-packages/hts/core/regressor.py in predict(self, exogenous_df, steps_ahead, distributor, disable_progressbar, show_warnings, **predict_kwargs)
350 self.hts_result.errors = (key, error)
351 self.hts_result.residuals = (key, residual)
--> 352 return self._revise(steps_ahead=steps_ahead)
353
354 def _revise(self, steps_ahead: int = 1) -> pandas.DataFrame:

~/.local/lib/python3.6/site-packages/hts/core/regressor.py in _revise(self, steps_ahead)
357 forecasts=self.hts_result.forecasts,
358 mse=self.hts_result.errors,
--> 359 nodes=self.nodes,
360 )
361

~/.local/lib/python3.6/site-packages/hts/revision.py in revise(self, forecasts, mse, nodes)
77
78 elif self.name == MethodT.FP.name:
---> 79 return forecast_proportions(forecasts, nodes)
80
81 else:

~/.local/lib/python3.6/site-packages/hts/functions.py in forecast_proportions(forecasts, nodes)
223 fore_sum = fore_sum[:, np.newaxis]
224 if column == 0:
--> 225 rev_top = np.array(forecasts["total"].yhat)
226 rev_top = rev_top[:, np.newaxis]
227 else:

KeyError: 'total'

Desktop (please complete the following information):

  • OS: Windows
  • scikit-hts version: 0.5.11
  • Python version: 3.6.9

Additional context
Perhaps, the total in the forecast_proportions method should be replaced with the root parameter passed in the fit method.

@aakashparsi aakashparsi added the bug Something isn't working label Jun 14, 2021
@carlomazzaferro
Copy link
Owner

Seems like the right diagnostic. Every instance of hardcoded "root" in the functions.py file should be replaced via param. I'm backed up, you think you could give this a go? @aakashparsi

@aakashparsi
Copy link
Collaborator Author

aakashparsi commented Jun 14, 2021

I think I can spend some time on this later next week due to the current work items I have for this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants