Seasonal Patterns
Learn the basics of seasonal patterns and how to identify it.
We'll cover the following...
Understanding seasonal patterns
Seasonal patterns (or seasonality) refer to periodical patterns in the data. Weather data, for example, is very seasonal, with average temperatures tending to be close for the same month, regardless of the year.
Now that we know how to decompose a time series into its fundamental components using seasonal_decompose
, let's break down the function parameters and results.
Press + to interact
main.py
microsoft_stock.csv
import pandas as pdimport matplotlib.pyplot as pltfrom statsmodels.tsa.seasonal import seasonal_decomposedf = pd.read_csv('microsoft_stock.csv')# Changing the datatypedf["Date"] = pd.to_datetime(df['Date'], format='%m/%d/%Y %H:%M:%S')# Setting the Date as indexdf = df.set_index('Date')# Seasonal decompositionresult = seasonal_decompose(df['Close'],model='additive',period=365,extrapolate_trend='freq')# Plotfig = result.plot(observed=False)# Displayfig.savefig("output/output.png")plt.close(fig)
First, we have
df['Close']
, which is our time series.Then, there’s
model
, which can take two possible values:'multiplicative'
and'additive'
.The multiplicative model will treat each value in the time series as the product of trend, seasonality, and residual.
...