LoslegenKostenlos loslegen

Time series decomposition

When visualizing time series data, you should look out for some distinguishable patterns:

  • seasonality: does the data display a clear periodic pattern?
  • trend: does the data follow a consistent upwards or downward slope?
  • noise: are there any outlier points or missing values that are not consistent with the rest of the data?

You can rely on a method known as time-series decomposition to automatically extract and quantify the structure of time-series data. The statsmodels library provides the seasonal_decompose() function to perform time series decomposition out of the box.

decomposition = sm.tsa.seasonal_decompose(time_series)

You can extract a specific component, for example seasonality, by accessing the seasonal attribute of the decomposition object.

Diese Übung ist Teil des Kurses

Visualizing Time Series Data in Python

Kurs anzeigen

Anleitung zur Übung

  • Import statsmodels.api using the alias sm.
  • Perform time series decomposition on the co2_levels DataFrame into a variable called decomposition.
  • Print the seasonality component of your time series decomposition.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Import statsmodels.api as sm
import ____ as ____

# Perform time series decompositon
decomposition = sm.tsa.____(____)

# Print the seasonality component
print(____)
Code bearbeiten und ausführen