YenLinWu / Time_Series_Model

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Statistical Time Series Model

ARIMA Model
  • Order Selection of ARIMA Model
  • ARIMA Modelling Procedure
    (1) Plot the data and identify any unusual observations.
    (2) If necessary, transform the data (using a Box-Cox Transformation) to stabilise the variance.
    (3) If the data are non-stationary, take first differences of the data until the data are stationary.
    (4) Examine the ACF/PACF: Is an ARIMA( p, d, 0 ) or ARIMA( 0, d, q ) model appropriate?
    (5) Try your chosen model(s), and use the AICc to search for a better model.
    (6) Check the residuals from your chosen model by plotting the ACF of the residuals, and doing a portmanteau test of the residuals. If they do not look like white noise, try a modified model.
    (7) Once the residuals look like white noise, calculate forecasts.
    Example: Seasonally adjusted electrical equipment orders
SARIMAX Model
  • How to use SARIMA in Python ? There are the following three steps to use SARIMAX model via Statsmodels library:
    (i) Define the model.
    (ii) Fit the defined model.
    (iii) Make a prediction with the fit model.
from statsmodels.tsa.statespace.sarimax import SARIMAX  
  
# Define model
'''
endog : observed time-series variable  
exog : exogenous variables
order : (p, d, q)
seasonal_order : (P, D, Q, S)  
trend : this parameter for controlling the deterministic trend polynomial A(t) as one of 'n','c','t','ct' for no trend, constant, linear, and constant with linear trend, respectively.
'''  
model = SARIMAX( endog, exog, order, seasonal_order, trend, ... )   
  
# Fit model
model_fit = model.fit()  

# One step forecast 
yhat = model_fit.predict( start, end )

References

[1] Forecasting: Principles and Practice (2nd ed online version)( 簡體中文版 ), Rob J Hyndman and George Athanasopoulos
[2] statsmodels v0.13.0.dev0
[3] statsmodels.tsa.statespace.sarimax.SARIMAX

Further Readings

[1] Summary of rules for identifying ARIMA models, Robert Nau.
[2] ARIMA Model – Complete Guide to Time Series Forecasting in Python, Selva Prabhakaran, Aug 22, 2021.
[3] A Gentle Introduction to SARIMA for Time Series Forecasting in Python, Jason Brownlee, Aug 18, 2018.
[4] How to Grid Search SARIMA Hyperparameters for Time Series Forecasting, Jason Brownlee, Oct 24, 2018.
[5] Inflation Forecasting, Swati Sethee, Jun 8, 2020.
[6] Complete Guide To SARIMAX in Python for Time Series Modeling, Yugesh Verma, Jul 30, 2021.
[7] End-to-End Time Series Analysis and Forecasting: a Trio of SARIMAX, LSTM and Prophet (Part 1), Bruce Nguyen, Feb 7, 2021.

About

License:MIT License


Languages

Language:Jupyter Notebook 100.0%