Olivier
12/16/2024, 7:16 PMunique_id
as index column. Simply put, your input data should always be a flat table without an index.
Thanks to MarcoGorelli for helping with Narwhals implementation, which has allowed us to implement Polars swiftly!
Questions or suggestions for new features? Let us know as a comment or file an issue on Github. Our priority for the next release is adding temporal hierarchical reconciliation methods, but open to suggestions otherwise!
Happy forecasting!Brandon Barber
12/18/2024, 10:57 PMunique_id
as an index column, I'm now running into issues when using reconciliarion methods that depend on Y_df.
For example:
reconcilers = [
BottomUp(),
MinTrace(method='wls_var'),
]
# reconcile forecasts
hrec = HierarchicalReconciliation(reconcilers=reconcilers)
Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df[['unique_id','ds','y_pred']],
Y_df=Y_train_df[['unique_id','ds','y_pred','y']],
S=S_df, tags=tags)
Gives me the error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[95], line 23
21 # reconcile forecasts
22 hrec = HierarchicalReconciliation(reconcilers=reconcilers)
---> 23 Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df[['unique_id','ds','q50']],
24 Y_df=Y_fitted_df[['unique_id','ds','q50','y']],
25 S=S_df, tags=tags)
File ~/anaconda3/lib/python3.10/site-packages/hierarchicalforecast/core.py:374, in HierarchicalReconciliation.reconcile(self, Y_hat_df, S, tags, Y_df, level, intervals_method, num_samples, seed, is_balanced, id_col, time_col, target_col)
370 if any_sparse and not nw.dependencies.is_pandas_dataframe(Y_df):
371 raise ValueError(
372 "You have one or more sparse reconciliation methods. Please convert `Y_df` to a pandas DataFrame."
373 )
--> 374 y_insample = self._prepare_Y(
375 Y_nw=Y_nw,
376 S_nw=S_nw,
377 is_balanced=is_balanced,
378 id_col=id_col,
379 time_col=time_col,
380 target_col=target_col,
381 )
382 reconciler_args["y_insample"] = y_insample
384 Y_tilde_nw = nw.maybe_reset_index(Y_hat_nw.clone())
...
-> 6130 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
6132 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
6133 raise KeyError(f"{not_found} not in index")
KeyError: "None of [MultiIndex([('y', 1577836800000000000),\n ('y', 1580515200000000000),\n ('y', 1583020800000000000),\n ('y', 1585699200000000000),\n ('y', 1588291200000000000),\n ('y', 1590969600000000000),\n ('y', 1593561600000000000),\n ('y', 1596240000000000000),\n ('y', 1598918400000000000),\n ('y', 1601510400000000000),\n ('y', 1604188800000000000),\n ('y', 1606780800000000000),\n ('y', 1609459200000000000),\n ('y', 1612137600000000000),\n ('y', 1614556800000000000),\n ('y', 1617235200000000000),\n ('y', 1619827200000000000),\n ('y', 1622505600000000000),\n ('y', 1625097600000000000),\n ('y', 1627776000000000000),\n ('y', 1630454400000000000),\n ('y', 1633046400000000000),\n ('y', 1635724800000000000),\n ('y', 1638316800000000000),\n ('y', 1640995200000000000),\n ('y', 1643673600000000000),\n ('y', 1646092800000000000),\n ('y', 1648771200000000000),\n ('y', 1651363200000000000),\n ('y', 1654041600000000000),\n ('y', 1656633600000000000),\n ('y', 1659312000000000000),\n ('y', 1661990400000000000),\n ('y', 1664582400000000000)],\n names=[None, 'ds'])] are in the [columns]"
All works fine when I can avoid using Y_dfOlivier
12/19/2024, 1:52 PMOlivier
12/19/2024, 2:41 PM....
contain the critical piece of information that I need to find out where the error occurs.Anthony Giorgio
01/02/2025, 3:42 PMOlivier
01/02/2025, 5:54 PMOlivier
01/02/2025, 5:55 PMAnthony Giorgio
01/02/2025, 6:19 PMpu xu
02/24/2025, 3:24 AMKeyError: "None of [MultiIndex([('y', 1577836800000000000),\n ('y', 1580515200000000000),\n ('y', 1583020800000000000),\n ('y', 1585699200000000000),\n ('y', 1588291200000000000),\n ('y', 1590969600000000000),\n ('y', 1593561600000000000),\n ('y', 1596240000000000000),\n ('y', 1598918400000000000),\n ('y', 1601510400000000000),\n ('y', 1604188800000000000),\n ('y', 1606780800000000000),\n ('y', 1609459200000000000),\n ('y', 1612137600000000000),\n ('y', 1614556800000000000),\n ('y', 1617235200000000000),\n ('y', 1619827200000000000),\n ('y', 1622505600000000000),\n ('y', 1625097600000000000),\n ('y', 1627776000000000000),\n ('y', 1630454400000000000),\n ('y', 1633046400000000000),\n ('y', 1635724800000000000),\n ('y', 1638316800000000000),\n ('y', 1640995200000000000),\n ('y', 1643673600000000000),\n ('y', 1646092800000000000),\n ('y', 1648771200000000000),\n ('y', 1651363200000000000),\n ('y', 1654041600000000000),\n ('y', 1656633600000000000),\n ('y', 1659312000000000000),\n ('y', 1661990400000000000),\n ('y', 1664582400000000000),\n ('y', 1667260800000000000),\n ('y', 1669852800000000000),\n ('y', 1672531200000000000),\n ('y', 1675209600000000000),\n ('y', 1677628800000000000),\n ('y', 1680307200000000000),\n ('y', 1682899200000000000),\n ('y', 1685577600000000000),\n ('y', 1688169600000000000),\n ('y', 1690848000000000000),\n ('y', 1693526400000000000),\n ('y', 1696118400000000000),\n ('y', 1698796800000000000),\n ('y', 1701388800000000000),\n ('y', 1704067200000000000),\n ('y', 1706745600000000000),\n ('y', 1709251200000000000),\n ('y', 1711929600000000000),\n ('y', 1714521600000000000),\n ('y', 1717200000000000000),\n ('y', 1719792000000000000),\n ('y', 1722470400000000000),\n ('y', 1725148800000000000),\n ('y', 1727740800000000000),\n ('y', 1730419200000000000),\n ('y', 1733011200000000000)],\n names=[None, 'ds'])] are in the [columns]"
File <command-2311550170284745>, line 1
----> 1 Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df,Y_df=Y_fitted_df,S=S_df,tags=tags)
I'm wondering do you solve it finally? @Brandon BarberOlivier
02/24/2025, 9:32 AMpu xu
02/25/2025, 2:26 AMFrancesco
03/11/2025, 11:23 PMOlivier
03/12/2025, 4:08 AMFrancesco
03/12/2025, 11:05 AMFrancesco
03/12/2025, 11:07 AMOlivier
03/13/2025, 2:57 PMFrancesco
03/13/2025, 4:35 PMOlivier
03/13/2025, 4:52 PMFrancesco
03/13/2025, 5:02 PM