IniziaInizia gratis

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.

Questo esercizio fa parte del corso

ARIMA Models in Python

Visualizza il corso

Istruzioni dell'esercizio

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

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Import seasonal decompose
from ____ import ____

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

# Plot decomposition
____
plt.show()
Modifica ed esegui il codice