Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Visualizing Seasonality with Heatmaps | Section
Deconstructing Temporal Patterns

bookVisualizing Seasonality with Heatmaps

Veeg om het menu te tonen

Seasonality is a fundamental concept in time series analysis, describing patterns that repeat at regular intervals, such as daily, monthly, or yearly cycles. Recognizing these patterns is crucial for accurate forecasting and deeper understanding of the underlying processes in your data. Visualizing seasonality helps you spot recurring behaviors, outliers, and shifts in temporal dynamics that may not be obvious through raw numbers or simple line plots. One powerful way to visualize and interpret seasonality is with a heatmap, which can highlight cyclical trends and anomalies across different time scales.

123456789101112131415161718192021222324252627
import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt # Generate a sample time series dataset with clear seasonality np.random.seed(42) dates = pd.date_range(start="2018-01-01", end="2022-12-31", freq="D") seasonal_pattern = 10 + 5 * np.sin(2 * np.pi * dates.dayofyear / 365) noise = np.random.normal(0, 2, len(dates)) values = seasonal_pattern + noise df = pd.DataFrame({"date": dates, "value": values}) df["year"] = df["date"].dt.year df["month"] = df["date"].dt.month # Group by year and month, then calculate monthly averages monthly_avg = df.groupby(["year", "month"])["value"].mean().unstack() # Create a heatmap to visualize seasonality plt.figure(figsize=(10, 6)) sns.heatmap(monthly_avg, cmap="YlGnBu", annot=True, fmt=".1f", cbar_kws={'label': 'Average Value'}) plt.title("Seasonal Heatmap: Average Value by Month and Year") plt.xlabel("Month") plt.ylabel("Year") plt.tight_layout() plt.show()
copy

The heatmap you generated displays years on the y-axis and months on the x-axis, with each cell showing the average value for a specific month and year. By examining the color intensity and annotated values, you can quickly identify recurring seasonal patterns. For instance:

  • Warmer colors consistently appearing in the summer months across all years signal a regular seasonal increase;
  • Cooler colors in winter months suggest a recurring dip;
  • Outliers or anomalies may show up as unexpected color shifts that break the typical pattern.

This visual approach makes it much easier to interpret cyclical behaviors, compare seasonality across years, and spot any changes or disruptions in the pattern over time.

question mark

Which of the following best describes how a heatmap helps you identify seasonality in time series data?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 6

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 1. Hoofdstuk 6
some-alt