2
$\begingroup$

I am using an arima model to forecast sales of a given product in python, using statsmodels.tsa.arima.model.ARIMA Sales are daily, with a history of 2019 until today. The model is adjusting correctly to the past, however when performing the forecast, it returns a flat line, as in the image shown.

Is there a way for forecasting to follow the same trend as in the past?

Model application:

model = ARIMA(df_log, order=(2,1,1), seasonal_order=(1,1,1,7), freq = 'D')
        results = model.fit()
        forecast_arima = np.exp(results.predict(start = 0, end = len(group)+1, dynamic = False)).to_frame(g)

Plot: enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

Note that you are not getting a flat line. You are getting forecasts that show seasonal variation, specifically weekday patterns.

Your forecasts vary less than the historical data simply because there is little regularity that ARIMA can fit (especially since you pre-specify the model order - you may want to use an automatic order selection method, as in forecast::auto.arima() for R). "The same trend as in the past" is an unclear requirement - ARIMA simply does not find enough pattern to fit, although you could always add random noise to your forecasts to make them look more sophisticated (but be aware that this will of course make them worse). See this thread and links therein.

You may want to look through previous threads discussing "flat ARIMA" forecasts.

Your best bet is likely to model the sharp spikes if you know what drives them, e.g., using regression with ARIMA errors. Same for that strange trough at 2020-04 to 2020-05, which to me looks like a possible COVID-19 effect.

Finally, retail sales sometimes show (intra-weekly, as you modeled here, but also intra-yearly), so although this does not look obvious here (and in any case, modeling the peaks and troughs is more urgent), you may want to look through that tag and specialized models to deal with multiple seasonalities.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.