# Time-Series Forecasting of Seasonal Data Using Machine Learning Methods
## 3 Development of the Models  
### Sarima  
Seasonal Autoregressive Integrated Moving Average (SARIMA), or Seasonal ARIMA, is an extension of ARIMA that explicitly supports univariate time series data with a seasonal component. According to [39], the seasonal ARIMA model includes autoregressive and moving average terms at lag \(s\).  
The seasonal \(ARIMA(p,d,q)(P,D,Q)_{s}\) model can be most succinctly expressed using the backward shift operator.  
\[\Theta_{P}(B^{s})\theta_{p}(B)(1-B^{s})^{D}(1-B)^{d}x_{i}=\Phi_{Q}(B^{s})\phi_ {q}(B)\omega_{t}. \tag{2}\]  
In Equation (2), \(\Theta_{P},\ \theta_{p},\ \Phi_{Q}\) and \(\phi_{q}\) are polynomials of orders \(P,\ p,\ Q\) and \(q\), respectively. In general, the model is non-stationary, although, if \(D=d=0\) and the roots of the characteristic equation (polynomial terms on the left-hand side of Equation (1)) all exceed unity in absolute value, the resulting model would be stationary.  
Thus, it is necessary to check the original dataset for stationarity before using the method. This can be performed using the Augmented Dickey-Fuller (ADfuller) test. This test is based on a hypothesis, where, if the \(p\)-value is less than 0.05, then we can consider the time series stationary, and if the \(p\)-value is greater than 0.05, then the time series is non-stationary.  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**ID** & **Timestamp** & **Measurement** \\ \hline
0 & 12 December 2022 00:00:00 & 6.305967 \\
1 & 12 December 2022 01:00:00 & 5.355895 \\
2 & 12 December 2022 02:00:00 & 4.122726 \\
3 & 12 December 2022 03:00:00 & 3.546737 \\ \(\ldots\) & & \\
452 & 30 December 2022 20:00:00 & 6.578148 \\
453 & 30 December 2022 21:00:00 & 6.591513 \\
454 & 30 December 2022 20:00:00 & 6.785699 \\
455 & 30 December 2022 23:00:00 & 6.396174 \\
456 & 31 December 2022 00:00:00 & 6.322228 \\ \hline \hline \end{tabular}
\end{table}
Table 1: The slice of the entire dataset.  
Figure 2: Initial dataset with a breakdown into training and test samples.  
To perform the ADfuller test and implement the SARIMA method, the library stat-models is used [40]. ADfuller test result are as follows:  
Augmented Dickey-Fuller Test for SARIMA method  
1. ADF : -6.162488723252326  
2. P-Value : 7.118446442706881e-08  
3. Num Of Lags : 18  
4. Num Of Observations Used For ADF: 389  
5. Critical Values :  
1% : -3.447272819026727  
5% : -2.868998737588248  
10% : -2.5707433189709294  
Thus, the original time series is stationary.  
The selection of parameters \((p,d,q)(P,D,Q)\) can be performed automatically using the _auto_arima_ function of the pmdarima library [41]. The result of the function is:  
AutoARIMA. Performing stepwise search to minimize aic  
Best model: ARIMA(3,0,2)(0,1,2)[24]  
Total fit time: 865.904 seconds  
Where \(s=24\) is the period of the seasonal time series in hours.  
After the model is built considering the obtained optimal parameters, in order to make a prediction, it is sufficient to use the _get_forecast_ method of the model object, passing as a parameter the number of time counts, for which we need to obtain a prediction. Since the interval between the samples in the initial dataset is 1 h, and the forecast is made for 48 h, you should specify the input parameter steps = 48.  
Figure 11 (see Appendix A) shows the time series plot obtained with the SARIMA model (solid blue line on the plot) and the actual measurement values from the test data set (dark bullet marker on the plot). The Section 4 will give a quantitative assessment of the quality of this and subsequent predictive models.