Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

ARIMA Models in Python

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import seasonal decompose
from ____ import ____

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

# Plot decomposition
____
plt.show()
Code bewerken en uitvoeren