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: _calculate_sigma() explicitly handles series with 1 data point (n=0) #699

Merged
merged 2 commits into from
Nov 14, 2023
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
9 changes: 6 additions & 3 deletions nbs/src/utils.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@
" return pred_int\n",
"\n",
"def _calculate_sigma(residuals, n): \n",
" sigma = np.nansum(residuals ** 2) \n",
" sigma = sigma / n\n",
" sigma = np.sqrt(sigma)\n",
" if n>0:\n",
" sigma = np.nansum(residuals ** 2) \n",
" sigma = sigma / n\n",
" sigma = np.sqrt(sigma)\n",
" else:\n",
" sigma = 0\n",
" return sigma"
]
},
Expand Down
11 changes: 7 additions & 4 deletions statsforecast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,15 @@ def _calculate_intervals(out, level, h, sigmah):


def _calculate_sigma(residuals, n):
sigma = np.nansum(residuals**2)
sigma = sigma / n
sigma = np.sqrt(sigma)
if n > 0:
sigma = np.nansum(residuals**2)
sigma = sigma / n
sigma = np.sqrt(sigma)
else:
sigma = 0
return sigma

# %% ../nbs/src/utils.ipynb 19
# %% ../nbs/src/utils.ipynb 20
class ConformalIntervals:
"""Class for storing conformal intervals metadata information."""

Expand Down
Loading