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 pdimport matplotlib.pyplot as pltfrom statsmodels.graphics.tsaplots import plot_acfdf = pd.read_csv('airpassengers.csv')# Changing the datatypedf["Month"] = pd.to_datetime(df['Month'], format='%Y-%m')# Setting the Date as indexdf = df.set_index('Month')# Plotting ACFfig,axe=plt.subplots(figsize=(6,5))axe.set_xlabel('Lag')axe.set_ylabel('Correlation')fig=plot_acf(df['Passengers'],ax=axe, alpha=0.05)# Displayfig.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 ...