...

/

Seasonal Patterns

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 pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose
df = pd.read_csv('microsoft_stock.csv')
# Changing the datatype
df["Date"] = pd.to_datetime(df['Date'], format='%m/%d/%Y %H:%M:%S')
# Setting the Date as index
df = df.set_index('Date')
# Seasonal decomposition
result = seasonal_decompose(
df['Close'],
model='additive',
period=365,
extrapolate_trend='freq'
)
# Plot
fig = result.plot(observed=False)
# Display
fig.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. (value=trendseasonalityresidual)(value = trend * ...