Francisco
10/17/2023, 3:30 AMJason Gofford
10/18/2023, 1:22 PMY_test_df
because their length is lower than my horizon? At the moment, if I use aggregate
to create the hierarchy I end up in a "series differences" scenario because my S_df
has levels that do not exist in Y_train_df
(as they're only in Y_test_df
). I can filter S_df
to only include what's in Y_train_df
but then I think I lose the ability to extract the test-set forecasts for those shorter series. Is there a better way?Francisco
11/07/2023, 1:34 PMFrancisco
11/07/2023, 1:34 PMC:\Users\M330618\.conda\envs\Merck\lib\site-packages\hierarchicalforecast\methods.py:261: RuntimeWarning:
invalid value encountered in divide
C:\Users\M330618\.conda\envs\Merck\lib\site-packages\hierarchicalforecast\methods.py:687: UserWarning:
Replacing negative forecasts with zero.
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
Cell In[544], line 19
16 rec_model = HierarchicalReconciliation(reconcilers=reconcilers)
18 #crear matriz de reconciliación
---> 19 p_rec = rec_model.reconcile(Y_hat_df=forecast_agg, Y_df=train_agg, S=S_train, tags=tags)
File ~\.conda\envs\Merck\lib\site-packages\hierarchicalforecast\core.py:265, in HierarchicalReconciliation.reconcile(self, Y_hat_df, S, tags, Y_df, level, intervals_method, num_samples, seed, sort_df)
261 fcsts_model = reconciler.predict(S=reconciler_args['S'],
262 y_hat=reconciler_args['y_hat'], level=level)
263 else:
264 # Memory efficient reconciler's fit_predict
--> 265 fcsts_model = reconcile_fn(**kwargs, level=level)
267 # Parse final outputs
268 Y_tilde_df[recmodel_name] = fcsts_model['mean'].flatten()
File ~\.conda\envs\Merck\lib\site-packages\hierarchicalforecast\methods.py:761, in MinTrace.fit_predict(self, S, y_hat, idx_bottom, y_insample, y_hat_insample, sigmah, level, intervals_method, num_samples, seed, tags)
758 raise Exception('idx_bottom needed for nonnegative reconciliation')
760 # Fit creates P, W and sampler attributes
--> 761 self.fit(S=S,
762 y_hat=y_hat,
763 y_insample=y_insample,
764 y_hat_insample=y_hat_insample,
765 sigmah=sigmah,
766 intervals_method=intervals_method,
767 num_samples=num_samples,
768 seed=seed,
769 tags=tags, idx_bottom=idx_bottom)
771 return self._reconcile(S=S, P=self.P, y_hat=self.y_hat,
772 level=level, sampler=self.sampler)
File ~\.conda\envs\Merck\lib\site-packages\hierarchicalforecast\methods.py:706, in MinTrace.fit(self, S, y_hat, y_insample, y_hat_insample, sigmah, intervals_method, num_samples, seed, tags, idx_bottom)
703 bottom_fcts = np.apply_along_axis(lambda y_hat: solve_qp(G=G, a=a @ y_hat, C=C, b=b)[0],
704 axis=0, arr=y_hat)
705 if not np.all(bottom_fcts > -1e-8):
--> 706 raise Exception('nonnegative optimization failed')
707 # remove negative values close to zero
708 bottom_fcts = np.clip(np.float32(bottom_fcts), a_min=0, a_max=None)
Exception: nonnegative optimization failed
Francisco
11/07/2023, 1:35 PMFrancisco
11/07/2023, 1:37 PMYacoub Alatrash
11/09/2023, 8:14 PMYacoub Alatrash
11/10/2023, 7:36 PMToni Borders
11/14/2023, 4:54 PMTraceback (most recent call last):
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierarchFrcstEx.py”, line 14, in <module>
from hierarchicalforecast.methods import BottomUp, TopDown, MiddleOut
File “/Users/tmb/Library/Caches/pypoetry/virtualenvs/data-science-zw503lJq-py3.10/lib/python3.10/site-packages/hierarchicalforecast/methods.py”, line 14, in <module>
_from quadprog import solve_qp_
_ImportError: dlopen(/Users/tmb/Library/Caches/pypoetry/virtualenvs/data-science-zw503lJq-py3.10/lib/python3.10/site-packages/quadprog.cpython-310-darwin.so, 0x0002): tried: ‘/Users/tmb/Library/Caches/pypoetry/virtualenvs/data-science-zw503lJq-py3.10/lib/python3.10/site-packages/quadprog.cpython-310-darwin.so’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64’)), ‘/System/Volumes/Preboot/Cryptexes/OS/Users/tmb/Library/Caches/pypoetry/virtualenvs/data-science-zw503lJq-py3.10/lib/python3.10/site-packages/quadprog.cpython-310-darwin.so’ (no such file), ‘/Users/tmb/Library/Caches/pypoetry/virtualenvs/data-science-zw503lJq-py3.10/lib/python3.10/site-packages/quadprog.cpython-310-darwin.so’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64’))_
Toni Borders
11/21/2023, 12:07 PMTraceback (most recent call last):
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierFcst.py”, line 106, in <module>
_main(data, freq, metadata_str, account)_
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierFcst.py”, line 88, in main
_Y_df = aggregate(Y_df, spec)_
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierFcst.py”, line 81, in aggregate
_Y_df, S_df, tags = aggregate(Y_df, spec)_
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierFcst.py”, line 81, in aggregate
_Y_df, S_df, tags = aggregate(Y_df, spec)_
File “/Users/tmb/PycharmProjects/data-science/UFE/code/hierFcst.py”, line 81, in aggregate
_Y_df, S_df, tags = aggregate(Y_df, spec)_
[Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceededHere is my code:
def get_spec():
spec = [
['org'],
['org', 'account'],
['org','meter'],
['org','account','meter']
]
return spec
def aggregate(Y_df, spec):
Y_df, S_df, tags = aggregate(Y_df, spec)
Y_df = Y_df.reset_index()
def main(data):
Y_df = clean_data(data)
spec = get_spec()
Y_df = aggregate(Y_df, spec)
print(Y_df.head(20))
Any thoughts on what could be going wrong?Graeme Davidson
11/22/2023, 4:28 PMA
11/25/2023, 4:24 PMYacoub Alatrash
12/01/2023, 7:20 PMIsmail EL MASSI
12/13/2023, 10:52 PMIsmail EL MASSI
12/20/2023, 4:02 PMSlackbot
12/26/2023, 11:04 PMIsmail EL MASSI
12/27/2023, 9:53 PMToni Borders
01/15/2024, 10:10 PMGraeme Davidson
01/26/2024, 12:26 PMJD Money
02/05/2024, 7:03 AMToni Borders
02/07/2024, 4:29 PMY_hat_df = fcst.forecast(h=h, level=[95], fitted=True)
Y_fitted_df = fcst.forecast_fitted_values()
when doing a reconciliation as opposed to the original time series, Y_df?
Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df,
Y_df=Y_fitted_df, #Y_fitted_df or Y_train_df ?
S=S_df,
tags=tags)
The examples in the documentation show examples of both.
Thanks in advance.Bryce Davies
02/09/2024, 2:52 AMIrina
02/13/2024, 4:55 PMNaren Castellon
02/16/2024, 8:58 PMNaren Castellon
02/22/2024, 9:01 PMNaren Castellon
02/27/2024, 12:15 AMreconcilers = [BottomUp(),
TopDown(method='forecast_proportions'),
#MiddleOut(middle_level='STORE ID/CITY/CATEGORY', top_down_method='forecast_proportions'),
#MinTrace(method='ols'),
#OptimalCombination(method='ols')
]
hrec = HierarchicalReconciliation(reconcilers=reconcilers)
# Redes Neurales
Y_rec_nf = hrec.reconcile(Y_hat_df=Y_hat_nf, Y_df=Y_df, S=S_df, tags=tags, )
Doesn't make the reconcilersAnthony Gonzalez
02/29/2024, 8:42 PMGalvan Goh
03/22/2024, 3:19 AMJakov Glavac
04/11/2024, 8:57 AMmf = MLForecast(models=[xgb.XGBRegressor()],
freq='MS',
lags=[1,2,12,24],
date_features=['month'],
)
mf.fit(Y_train_df, fitted=True, prediction_intervals=PredictionIntervals(n_windows=10, h=horizon))
Y_hat_mf = mf.predict(horizon, level=level).set_index('unique_id')
insample_mf = mf.forecast_fitted_values()
Hi, I'm woundering if xgboost here predicts for each unique id with different if not, how to make it do so? Beacuse I want to avoid stuff like this where model predictions are ok for on level but on other thay are way off. I would appreciate point in right direction.victor michon
04/23/2024, 5:59 PM