Skip to content
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

[FEAT] NeuralForecast Compatibility and Example Notebook #188

Merged
merged 8 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions hierarchicalforecast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ def _reverse_engineer_sigmah(Y_hat_df, y_hat, model_name):
In the future, we might deprecate this function in favor of a
direct usage of an estimated $\hat{sigma}_{h}$
"""
drop_cols = ['ds', 'y'] if 'y' in Y_hat_df.columns else ['ds']

drop_cols = ['ds']
if 'y' in Y_hat_df.columns:
drop_cols.append('y')
if model_name+'-median' in Y_hat_df.columns:
drop_cols.append(model_name+'-median')
model_names = Y_hat_df.drop(columns=drop_cols, axis=1).columns.to_list()
pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name)]
pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name or '-median' in name)]
dluuo marked this conversation as resolved.
Show resolved Hide resolved
pi_model_name = [pi_name for pi_name in pi_model_names if model_name in pi_name]
pi = len(pi_model_name) > 0

Expand Down Expand Up @@ -143,7 +148,7 @@ def _prepare_fit(self,
if Y_hat_df[model_names].isnull().values.any():
raise Exception('`Y_hat_df` contains null values')

pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name)]
pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name or '-median' in name)]
model_names = [name for name in model_names if name not in pi_model_names]

# TODO: Complete y_hat_insample protection
Expand Down
11 changes: 8 additions & 3 deletions nbs/core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,14 @@
" In the future, we might deprecate this function in favor of a \n",
" direct usage of an estimated $\\hat{sigma}_{h}$\n",
" \"\"\"\n",
" drop_cols = ['ds', 'y'] if 'y' in Y_hat_df.columns else ['ds']\n",
"\n",
" drop_cols = ['ds']\n",
" if 'y' in Y_hat_df.columns:\n",
" drop_cols.append('y')\n",
" if model_name+'-median' in Y_hat_df.columns:\n",
" drop_cols.append(model_name+'-median')\n",
" model_names = Y_hat_df.drop(columns=drop_cols, axis=1).columns.to_list()\n",
" pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name)]\n",
" pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name or '-median' in name)]\n",
" pi_model_name = [pi_name for pi_name in pi_model_names if model_name in pi_name]\n",
" pi = len(pi_model_name) > 0\n",
"\n",
Expand Down Expand Up @@ -243,7 +248,7 @@
" if Y_hat_df[model_names].isnull().values.any():\n",
" raise Exception('`Y_hat_df` contains null values')\n",
" \n",
" pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name)]\n",
" pi_model_names = [name for name in model_names if ('-lo' in name or '-hi' in name or '-median' in name)]\n",
" model_names = [name for name in model_names if name not in pi_model_names]\n",
" \n",
" # TODO: Complete y_hat_insample protection\n",
Expand Down
Loading