scikit-hts icon indicating copy to clipboard operation
scikit-hts copied to clipboard

[BUG] KeyError when using custom root name

Open aakashparsi opened this issue 4 years ago • 2 comments

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 avatar Jun 14 '21 03:06 aakashparsi

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

carlomazzaferro avatar Jun 14 '21 07:06 carlomazzaferro

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

aakashparsi avatar Jun 14 '21 19:06 aakashparsi