Giter Club home page Giter Club logo

Comments (10)

jmoralez avatar jmoralez commented on May 27, 2024 1

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)

from hierarchicalforecast.

jmoralez avatar jmoralez commented on May 27, 2024

Hey @mjsandoval04. Do you have zeros in your insample predictions?

from hierarchicalforecast.

mjsandoval04 avatar mjsandoval04 commented on May 27, 2024

as a matter of fact yes I do have some "0" values in some of my in-sample predictions, corresponding to "0" sales values for that period, here is a snippet of my data.
I tried to put a small value like "1" and a large value of "1000" but still got "NaN" for the TopDown method.
what should I do?

image

from hierarchicalforecast.

jmoralez avatar jmoralez commented on May 27, 2024

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)?

from hierarchicalforecast.

mjsandoval04 avatar mjsandoval04 commented on May 27, 2024

I have checked my data several times and forecast results (the Y_hat_df and Y_df) When it comes to the forecast "CES" there are no "zeros" (as it should be) and in the in-sample df only "y" has the "0" meaning there is forecast greater than 0 for that period although the actual sales were "0".

I have tried adding values to the zeros in column "y" and still I'm getting NaN. For example for the zeros make "y" equals to "CES".
I also changed the forecasting method for example "SES" and I'm getting the same results.

to my understanding if CES (which is the forecast is greater than 0) then the TopDown should return a value. am I missing something?
image

from hierarchicalforecast.

jmoralez avatar jmoralez commented on May 27, 2024

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)

from hierarchicalforecast.

mjsandoval04 avatar mjsandoval04 commented on May 27, 2024

yes, the example described in the lib documentation worked for me as well.
here is Jupiter notebook and I've uploaded the data for your reference (here is the link for the excel files)

data: https://drive.google.com/drive/folders/1Ix_noPRb70KUaMtMy9LYu-4xxcdHwq5O?usp=sharing
Jupiter NB:
TopDown returns NaN_test.zip

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

from hierarchicalforecast.

mjsandoval04 avatar mjsandoval04 commented on May 27, 2024

Hello @jmoralez were u able to reproduce my example?

from hierarchicalforecast.

mjsandoval04 avatar mjsandoval04 commented on May 27, 2024

@jmoralez thank you for the feedback brother! it works flawlessly :)

from hierarchicalforecast.

github-actions avatar github-actions commented on May 27, 2024

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.

from hierarchicalforecast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.