A seasonal ARIMA model is formed by including additional seasonal terms in the ARIMA models. The additional seasonal terms are simply multiplied by the non-seasonal terms.
So this recipe is a short example on What is seasonal ARIMA model and how to use it. Let's get started.
import numpy as np import pandas as pd from statsmodels.tsa.seasonal import seasonal_decompose import matplotlib.pyplot as plt
Let's pause and look at these imports. Numpy and pandas are general ones. Here, seasonal_decompose will help us in understanding the seasonilty of data.
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date']).set_index('date')
Here, we have used one time series data from github. Also, we have set our index to date.
Now our dataset is ready.
decomposition = seasonal_decompose(df.value, freq=12) fig = plt.figure() fig = decomposition.plot() fig.set_size_inches(20, 10)
Here, we have broken our datset using seasonal_decompose into trend, residual and seasonal. Residual is the stationary pattern and will almost remain constant. Seasonal is what our seasonal pattern will be. Trend is just our upward or downward movement with time.
trend = decomposition.trend seasonal = decomposition.seasonal residual = decomposition.resid print(seasonal)
Apart from visualizing our pattern, we have produced various dataframes based on their patter. Finally, we have printed down our seasonal dataframe.
Once we run the above code snippet, we will see:
Srcoll down the ipython file to visualize the results.
Seasonal, Residual and Trend is visible. Also, we have produced our seasonal dataset in one separte dataframe for further analysis if needed.