SARIMA vs LSTM

Ishan Mazumder
3 min readAug 10, 2020

--

Time series forecasting using Traditional ML SARIMA model and also using Deep Learning network LSTM

Time and Tide waits for none

I was very curious to understand how LSTM model would perform against a move coveted SARIMA model. But after doing this project i was very clear on what kind of model i should be choosing for my next Time series Forecasting project. So lets get into the details.

The data set which i have used is of a retailer who sells Rose wine. So here we don’t have to worry about any holidays or weekends in our data set and also no missing values :). After this we divide the Train and Test data. From now on we will be working on the Training data set only.

So i started building the SARIMA model after taking care of the data pre-processing and converting the index into date time format. After i decomposed the data its was clear that the data was an additive data, it didn’t show any property of exponential growth. Next thing i had to find was the seasonality of the data. So to find it out i looked at one years data and i could find the seasonality of the data.

Then i checked for Stationarity of the data using ADFuller Test. Initially data wasn’t stationary so used shifting of one to make it stationary, which determines our “D” value as 1.

Now we would also need “P,Q” for SARIMA model. To find out “P” used PACF plot and for and for “Q” used ACF plot.

I also used a Grid Search for the model with different “P,D,Q” values. The model with the lowest “AIC” value is the best model. You can find the details in the code. By now i have all the values which are needed to fit the SARIMA model. Then we predict the values using Test data and found the RMSE which was close to 16.6

Its now time to build the LSTM model and compare the models.

For every Neural Network model we have to first have to convert the scale of the data, here i used RobustScaler. We also need to convert the input dimension of the data for the LSTM model. The dimension should be 3-dimensional.

The sequence model which i built is a Bidirectional Many to Many LSTM model. Feel free to look at the code on my github account “https://github.com/IshanMazumder/SARIMA-vs-LSTM

After fitting the model, i checked it prediction. But remember before we find the error we need to do inverse scale for the predicted values. Once done we can find the RMSE which was around 17.05.

So to conclude SARIMA did bit better for Short Term prediction but LSTM would definately do better when it comes to Long term predictions.

You can also try the Prophet Model from FB. Let me know how it worked. The code and the data set in on my github account. Thanks for reading!

--

--