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

[FIX] Conformal prediction issues #1179

Merged
merged 6 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
240 changes: 3 additions & 237 deletions nbs/docs/tutorials/20_conformal_prediction.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nbs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"group":"Probabilistic Forecasting",
"pages":[
"docs/tutorials/uncertainty_quantification.html",
"docs/tutorials/longhorizon_probabilistic.html"
"docs/tutorials/longhorizon_probabilistic.html",
"docs/tutorials/conformal_prediction.html"
]
},
{
Expand Down
6 changes: 4 additions & 2 deletions nbs/utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@
" cuts = [alpha / 200 for alpha in reversed(alphas)]\n",
" cuts.extend(1 - alpha / 200 for alpha in alphas)\n",
" for model in model_names:\n",
" scores = cs_df[model].to_numpy().reshape(cs_n_windows, n_series, horizon)\n",
" scores = cs_df[model].to_numpy().reshape(n_series, cs_n_windows, horizon)\n",
" scores = scores.transpose(1, 0, 2)\n",
" # restrict scores to horizon\n",
" scores = scores[:,:,:horizon]\n",
" mean = fcst_df[model].to_numpy().reshape(1, n_series, -1)\n",
Expand Down Expand Up @@ -670,7 +671,8 @@
" cuts = [lv / 100 for lv in level]\n",
" for model in model_names:\n",
" mean = fcst_df[model].to_numpy().ravel()\n",
" scores = cs_df[model].to_numpy().reshape(cs_n_windows, n_series, horizon)\n",
" scores = cs_df[model].to_numpy().reshape(n_series, cs_n_windows, horizon)\n",
" scores = scores.transpose(1, 0, 2)\n",
" # restrict scores to horizon\n",
" scores = scores[:,:,:horizon]\n",
" quantiles = np.quantile(\n",
Expand Down
6 changes: 4 additions & 2 deletions neuralforecast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def add_conformal_distribution_intervals(
cuts = [alpha / 200 for alpha in reversed(alphas)]
cuts.extend(1 - alpha / 200 for alpha in alphas)
for model in model_names:
scores = cs_df[model].to_numpy().reshape(cs_n_windows, n_series, horizon)
scores = cs_df[model].to_numpy().reshape(n_series, cs_n_windows, horizon)
scores = scores.transpose(1, 0, 2)
# restrict scores to horizon
scores = scores[:, :, :horizon]
mean = fcst_df[model].to_numpy().reshape(1, n_series, -1)
Expand Down Expand Up @@ -538,7 +539,8 @@ def add_conformal_error_intervals(
cuts = [lv / 100 for lv in level]
for model in model_names:
mean = fcst_df[model].to_numpy().ravel()
scores = cs_df[model].to_numpy().reshape(cs_n_windows, n_series, horizon)
scores = cs_df[model].to_numpy().reshape(n_series, cs_n_windows, horizon)
scores = scores.transpose(1, 0, 2)
# restrict scores to horizon
scores = scores[:, :, :horizon]
quantiles = np.quantile(
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ language = English
custom_sidebar = True
license = apache2
status = 2
requirements = coreforecast>=0.0.6 fsspec numpy>=1.21.6 pandas>=1.3.5 torch>=2.0.0 pytorch-lightning>=2.0.0 ray[tune]>=2.2.0 optuna utilsforecast>=0.0.25
requirements = coreforecast>=0.0.6 fsspec numpy>=1.21.6 pandas>=1.3.5 torch>=2.0.0 pytorch-lightning>=2.0.0 ray[tune]>=2.2.0 optuna utilsforecast>=0.2.3
spark_requirements = fugue pyspark>=3.5
aws_requirements = fsspec[s3]
dev_requirements = black gitpython hyperopt matplotlib mypy nbdev==2.3.25 polars pre-commit pyarrow ruff s3fs transformers
Expand Down