[Utils] _calculate_sigma
has warning if series has 1 data point
#698
Labels
_calculate_sigma
has warning if series has 1 data point
#698
Hi! Issue Severity = None because now that I understand the warning, it's no problem! Please let me know any questions. And thanks all!
What happened + What you expected to happen
What happened
When I fit
Naive()
models to a dataframe consisting of series with 1 point each, I get intermittent warnings:RuntimeWarning: invalid value encountered in double_scalars. sigma = sigma / n
The warning occurs once. If I fit a fresh model to the same data 50 times, the warning only occurs once. Execute the loop again, zero warnings. But restart kernel, the loop throws one warning.
What I expected to happen
Forecasts looked as expected given the algorithm, and a Naive forecast on a series with one data point seems acceptable. But the warning made me look for a bug in my code or invalid data. The warning occurs when Naive().fit() calls _calculate_sigma(). I could see how we might get a divide by 0 or NaN issue in a standard deviation, but the intermittent nature of the warning was confusing, since this is a deterministic model fit to the same dataset.
From discussion with José on Nixtla Slack:
Naive()
to a series with only 1 data point. After the chat I understood how then
passed to_calculate_sigma()
is the series length - 1, so with my datasetn=0
, andsigma / n
divides by zero, throwing the warning.warnings
module, but the divide by zero occurs every time.José's suggestion:
Versions / Dependencies
statsforecast 1.5.0 and 1.6.0
A Python 3.8 image on SageMaker
Also reproduced in Colab with Python 3.10.12, statsforecast 1.6.0
Reproduction script
Issue Severity
None
The text was updated successfully, but these errors were encountered: