-
Notifications
You must be signed in to change notification settings - Fork 69
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
TopDown returns NaN #255
Comments
Hey @mjsandoval04. Do you have zeros in your insample predictions? |
What about for CES? I think there's a division by zero going on. Can you try adding some small values to both columns (y and CES)? |
Can you provide a reproducible example? The following works fine: import numpy as np
import pandas as pd
from hierarchicalforecast.core import HierarchicalReconciliation
from hierarchicalforecast.methods import TopDown
from hierarchicalforecast.utils import aggregate
df = pd.read_csv('https://raw.githubusercontent.com/Nixtla/transfer-learning-time-series/main/datasets/tourism.csv')
df = df.rename({'Trips': 'y', 'Quarter': 'ds'}, axis=1)
df.insert(0, 'Country', 'Australia')
spec = [
['Country'],
['Country', 'State'],
['Country', 'State', 'Region'],
]
y_df, s_df, tags = aggregate(df, spec)
y_df = y_df.reset_index()
y_df.loc[y_df['unique_id'] == 'Australia', 'y'] = 0.1
y_df['model'] = np.random.rand(y_df.shape[0])
valid = y_df.groupby('unique_id').tail(12)
train = y_df.drop(valid.index)
hrec = HierarchicalReconciliation(reconcilers=[TopDown(method='average_proportions')])
hrec.reconcile(Y_hat_df=valid, Y_df=train, S=s_df, tags=tags) |
yes, the example described in the lib documentation worked for me as well. data: https://drive.google.com/drive/folders/1Ix_noPRb70KUaMtMy9LYu-4xxcdHwq5O?usp=sharing PS, apologies I'm a newbie when it comes to GitHub I don't know how to paste the code as you did so I just uploaded the files |
Hello @jmoralez were u able to reproduce my example? |
Yes, you have a serie that is shorter than the others which produces null values in data2. You can use the following to add the missing dates and fill them with zero: # %pip install utilsforecast if necessary
from utilsforecast.preprocessing import fill_gaps
data2['ds'] = pd.to_datetime(data2['ds'])
data2_filled = fill_gaps(data2.reset_index(), start='global', end='global', freq='M')
data2_filled = data2_filled.fillna(0)
p_rec = rec_model.reconcile(Y_hat_df=data1, Y_df=data2_filled, S=S_train, tags=tags) |
@jmoralez thank you for the feedback brother! it works flawlessly :) |
This issue has been automatically closed because it has been awaiting a response for too long. When you have time to to work with the maintainers to resolve this issue, please post a new comment and it will be re-opened. If the issue has been locked for editing by the time you return to it, please open a new issue and reference this one. |
@jmoralez thanks for the response, in my case, my code was correct I provided the in-sample predictions in Y_df but still the TopDown results are "NaN". it works for the BottomUp and other methods that I tested like "OptimalCombination" and "MinTrace". So it is strange that is returning NaN for the TopDown method.
any recommendation, please ? below is a snippet of my code:
Originally posted by @mjsandoval04 in #253 (comment)
The text was updated successfully, but these errors were encountered: