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

[question] Division by Zero error #32

Closed
tackes opened this issue Feb 24, 2022 · 5 comments · Fixed by #259
Closed

[question] Division by Zero error #32

tackes opened this issue Feb 24, 2022 · 5 comments · Fixed by #259

Comments

@tackes
Copy link

tackes commented Feb 24, 2022

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?

@AzulGarza
Copy link
Member

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 AzulGarza added the bug label Feb 24, 2022
@tackes
Copy link
Author

tackes commented Feb 24, 2022

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()`

@mergenthaler
Copy link
Member

@all-contributors please add @tackes for bug

@allcontributors
Copy link
Contributor

@mergenthaler

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

@blazespinnaker
Copy link

blazespinnaker commented Feb 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants