CommencerCommencer gratuitement

Seasonal decompose

You can think of a time series as being composed of trend, seasonal and residual components. This can be a good way to think about the data when you go about modeling it. If you know the period of the time series you can decompose it into these components.

In this exercise you will decompose a time series showing the monthly milk production per cow in the USA. This will give you a clearer picture of the trend and the seasonal cycle. Since the data is monthly you will guess that the seasonality might be 12 time periods, however this won't always be the case.

The milk production time series has been loaded in to the DataFrame milk_production and is available in your environment.

Cet exercice fait partie du cours

ARIMA Models in Python

Afficher le cours

Instructions

  • Import the seasonal_decompose() function from statsmodels.tsa.seasonal.
  • Decompose the 'pounds_per_cow' column of milk_production using an additive model and period of 12 months.
  • Plot the decomposition.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import seasonal decompose
from ____ import ____

# Perform additive decomposition
decomp = seasonal_decompose(___, 
                            period=____)

# Plot decomposition
____
plt.show()
Modifier et exécuter le code