Comments (10)
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.
Hey @mjsandoval04. Do you have zeros in your insample predictions?
from hierarchicalforecast.
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?
from hierarchicalforecast.
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.
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?
from hierarchicalforecast.
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.
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.
Hello @jmoralez were u able to reproduce my example?
from hierarchicalforecast.
@jmoralez thank you for the feedback brother! it works flawlessly :)
from hierarchicalforecast.
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)
- TopDown Approach doesn't raise Exception as expected with `method="forecast_proportions"`
- Test sets includes y as defined
- Exception: min_trace (wls_var) needs covariance matrix to be positive definite. HOT 6
- [utils] aggregate doesn't work correctly with most recent version of the code HOT 1
- `MinTrace` fails for zero-inflated Time Series with `res_methods` in `['wls_var', 'mint_cov', 'mint_shrink']` HOT 2
- Update evaluation example in `README`
- hierarchicalforecast.core - 'list' object has no attribute 'insample' - HOT 2
- Sparse Methods Missing from 0.3.0 HOT 3
- StatsForecast models producing NotImplementedError: tiny datasets in 0.4.0 HOT 5
- MinTraceSparse(nonnegative=True) HOT 1
- [Core][Enhancement]: Add dummies to Aggregate
- Add temporal hierarchies HOT 2
- [Core] not balancing when doing aggregate() HOT 3
- [Core] KaTex parse error: Can't use function '$' in math mode
- Wrong argument name in evaluation section of README
- [utils] HierarchicalPlot is not plotting HOT 1
- TopDown method (proportion_averages, average_proportions) broken in 0.3.0, 0.4.0 and 0.4.1 HOT 6
- dependency on `quadprog` HOT 6
- [Core] Possible issue with core.py HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hierarchicalforecast.