Autocorrelation#
Goal
Identify dominant periodicities in a time series using autocorrelation. Peaks in the autocorrelation function (ACF) reveal repeating cycles — daily, weekly, or seasonal — which are fundamental to understanding building energy and climate data.
Data Basis
Dataset: flatTempHum.csv — Hourly indoor temperature and humidity measurements from four residential flats (A–D).
Column used: FlatA_Temp
Time range: October 2018 – September 2020
Data Preparation#
import pandas as pd
url = "https://raw.githubusercontent.com/retomarek/edap/main/edap/sampleData/flatTempHum.csv"
df = pd.read_csv(url, sep=";")
df["time"] = pd.to_datetime(df["time"])
df = df.set_index("time", drop=True)
df.head()
| FlatA_Hum | FlatA_Temp | FlatB_Hum | FlatB_Temp | FlatC_Hum | FlatC_Temp | FlatD_Hum | FlatD_Temp | |
|---|---|---|---|---|---|---|---|---|
| time | ||||||||
| 2018-10-03 00:00:00 | 53.0 | 24.43 | 38.8 | 22.40 | 44.0 | 24.5 | 49.0 | 24.43 |
| 2018-10-03 01:00:00 | 53.0 | 24.40 | 38.8 | 22.40 | 44.0 | 24.5 | 49.0 | 24.40 |
| 2018-10-03 02:00:00 | 53.0 | 24.40 | 39.3 | 22.40 | 44.7 | 24.5 | 48.3 | 24.38 |
| 2018-10-03 03:00:00 | 53.0 | 24.40 | 40.3 | 22.40 | 45.0 | 24.5 | 48.0 | 24.33 |
| 2018-10-03 04:00:00 | 53.3 | 24.40 | 41.0 | 22.37 | 45.2 | 24.5 | 47.7 | 24.30 |
Visualization#
The autocorrelation plot shows how a signal correlates with itself at increasing time lags. The blue shaded area marks the 95% confidence interval — values inside the band are not statistically significant.
from pyedautils.plots import plot_autocorrelation
fig = plot_autocorrelation(
df,
column="FlatA_Temp",
lags=168,
title="Autocorrelation — FlatA Temperature (1 week)",
)
fig.show()
Reading the autocorrelation plot
Peak at lag 24 → daily cycle (temperature now resembles temperature 24 hours ago)
Peak at lag 168 → weekly cycle (same day last week)
Slow overall decay → strong trend in the data (non-stationary)
Residential buildings typically show a clear daily cycle but a weak weekly cycle (no weekday/weekend occupancy difference)
Longer Lag Window#
Increase the number of lags to look for longer-period cycles.
fig = plot_autocorrelation(
df,
column="FlatA_Temp",
lags=720,
title="Autocorrelation — FlatA Temperature (30 days)",
height=350,
)
fig.show()
Customization
Lags count steps of the regular time grid that
plot_autocorrelationbuilds itself; gaps of up tomax_gapsteps (default 6) are interpolated, longer gaps are left out of the calculation.Set
lags=24for a single-day view.Set
lags=8760to check for annual cycles (requires at least 2 years of hourly data).The confidence band widens at higher lags because it adds up the autocorrelations at all shorter lags (Bartlett’s formula): in a strongly autocorrelated series, a single peak at a long lag is harder to tell from chance.