Common Patterns

Learn some common patterns in time series data and how to interpret them.

We'll cover the following...

Seasonality

The first pattern we'll learn involves identifying seasonality. As we have seen, seasonality is essentially a pattern that repeats in regular intervals of time. Sometimes this pattern will be visible when we plot the line chart, but not always. A good way to spot this is by looking at the autocorrelogram.

Press + to interact
main.py
airpassengers.csv
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf
df = pd.read_csv('airpassengers.csv')
# Changing the datatype
df["Month"] = pd.to_datetime(df['Month'], format='%Y-%m')
# Setting the Date as index
df = df.set_index('Month')
# Plotting ACF
fig,axe=plt.subplots(figsize=(6,5))
axe.set_xlabel('Lag')
axe.set_ylabel('Correlation')
fig=plot_acf(df['Passengers'],ax=axe, alpha=0.05)
# Display
fig.savefig("output/output.png")
plt.close(fig)

Remember how the airline passengers' data was seasonal? Notice how this autocorrelogram is different than the one from the stock prices' data, with a ...