statsforecast icon indicating copy to clipboard operation
statsforecast copied to clipboard

[question] Division by Zero error

Open tackes opened this issue 2 years ago • 4 comments

When running on many groups of time series, some groups are giving me a 'division by zero' error, and the script stops. Is there a way to pass through this error and complete the forecasts without errors?

tackes avatar Feb 24 '22 18:02 tackes

Hi @tackes! Would it be possible for you to share with us any time series that gives you the error? To try to replicate and debug it :)

AzulGarza avatar Feb 24 '22 18:02 AzulGarza

The issue is with short time series. The below will return 2 errors -

  1. random_walk_with_drift will return a divide by zero error.
  2. arima will return math domain error

In the code sample, once removing the 'test' period, it will only have 1 data point to do calculations. What would be a nice feature is if there was an option to 'ignore errors' and keep processing. This particular time series was on the 812th time series group out of 2000, but because it hit an error, the entire script stops running. Even better is if there was a logging feature to store what and where the error occurred.

`data = {'unique_id': ['A','A','A','A','A'], 'y':[128050,4200,0,0,0], 'ds': pd.date_range(end='2021-09-01', periods=5, freq='M')} series = pd.DataFrame(data, columns =['unique_id','y','ds'])

series_test = test_df.groupby('unique_id').tail(horizon).copy() series = test_df.drop(series_test.index) series['unique_id'] = series['unique_id'].astype('object')

series = series.set_index('unique_id') seasonality = 12 #Monthly data models = [ random_walk_with_drift, auto_arima]

fcst = StatsForecast(df=series, models=models, freq='M', n_jobs=1) forecasts = fcst.forecast(horizon) forecasts.reset_index()`

tackes avatar Feb 24 '22 19:02 tackes

@all-contributors please add @tackes for bug

mergenthaler avatar Feb 28 '22 23:02 mergenthaler

@mergenthaler

I've put up a pull request to add @tackes! :tada:

allcontributors[bot] avatar Feb 28 '22 23:02 allcontributors[bot]

division by zero

Get this error as well quite frequently,

StatsForecast( models = [AutoARIMA(season_length = 3)], freq = 'M')

unique_id ds y 40041 2021-10-01 2.607948 40041 2021-09-01 2.613875 40041 2021-08-01 2.646475 40041 2021-07-01 2.667220 40041 2021-06-01 2.673147 40041 2021-05-01 2.705746 40041 2021-04-01 2.693892 40041 2021-03-01 2.735382 40041 2021-02-01 2.690929 40041 2021-01-01 2.578313

unique_id 31179 2021-10-01 1.959469 31179 2021-09-01 1.972889 31179 2021-08-01 1.999731 31179 2021-07-01 1.972889 31179 2021-06-01 1.986311 31179 2021-05-01 2.013153 31179 2021-04-01 2.026574 31179 2021-03-01 2.133942 31179 2021-02-01 2.107100 31179 2021-01-01 2.133942

              ds         y

unique_id 22009 2021-10-01 1.516322 22009 2021-09-01 1.503445 22009 2021-08-01 1.513103 22009 2021-07-01 1.477690 22009 2021-06-01 1.464812 22009 2021-05-01 1.442277 22009 2021-04-01 1.422961 22009 2021-03-01 1.352135 22009 2021-02-01 1.348915 22009 2021-01-01 1.345696

              ds         y

unique_id 31105 2021-10-01 2.068724 31105 2021-09-01 2.068724 31105 2021-08-01 2.068724 31105 2021-07-01 2.033661 31105 2021-06-01 2.033661 31105 2021-05-01 2.103787 31105 2021-04-01 2.208976 31105 2021-03-01 2.279102 31105 2021-02-01 2.208976 31105 2021-01-01 2.664797

blazespinnaker avatar Feb 01 '23 00:02 blazespinnaker