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

ignore zeros on mape calculation #89

Merged
merged 8 commits into from
Jun 19, 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
3 changes: 1 addition & 2 deletions nbs/losses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@
" .sub(df[target_col], axis=0)\n",
" .abs()\n",
" .div(_zero_to_nan(df[target_col].abs()), axis=0)\n",
" .fillna(0)\n",
" .groupby(df[id_col], observed=True).mean()\n",
" )\n",
" res.index.name = id_col\n",
Expand All @@ -662,7 +661,7 @@
" abs_err = pl.col(target_col).sub(pl.col(model)).abs()\n",
" abs_target = _zero_to_nan(pl.col(target_col))\n",
" ratio = abs_err.truediv(abs_target).alias(model)\n",
" return ratio.fill_nan(0)\n",
" return ratio.fill_nan(None)\n",
"\n",
" res = _pl_agg_expr(df, models, id_col, gen_expr)\n",
" return res"
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ user = Nixtla
requirements = numpy packaging pandas>=1.1.1
plotting_requirements = pandas[plot] plotly plotly-resampler
scalers_requirements = numba scipy
polars_requirements = polars
polars_requirements = polars numpy<2
dev_requirements = datasetsforecast==0.0.8 nbdev pyarrow
readme_nb = index.ipynb
allowed_metadata_keys =
Expand Down
3 changes: 1 addition & 2 deletions utilsforecast/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def mape(
.sub(df[target_col], axis=0)
.abs()
.div(_zero_to_nan(df[target_col].abs()), axis=0)
.fillna(0)
.groupby(df[id_col], observed=True)
.mean()
)
Expand All @@ -183,7 +182,7 @@ def gen_expr(model):
abs_err = pl.col(target_col).sub(pl.col(model)).abs()
abs_target = _zero_to_nan(pl.col(target_col))
ratio = abs_err.truediv(abs_target).alias(model)
return ratio.fill_nan(0)
return ratio.fill_nan(None)

res = _pl_agg_expr(df, models, id_col, gen_expr)
return res
Expand Down
Loading