I'm working on the analysis of a dataset containing time series of hourly traffic congestion in a certain city, during a period of 23 years (number of data points: Roughly 24 X 365 X 23 = 201480). I wanted to spot annual seasonality in the data, so I used:

from statsmodels.tsa.seasonal import seasonal_decompose

daily_avg_cong = df.groupby("Date")["Hourly_cong"].mean().reset_index()
ts = daily_avg_cong['Hourly_cong']
result = seasonal_decompose(ts, model='additive', period=365, extrapolate_trend='freq')

Trend and Seasonality seem to reflect the data properly - the trend shows the expected increase over the years, and the Seasonal component shows a cyclic pattern that is in line with what I would expect from observing the data. My problem is the magnitude of the Residuals, especially compared to the Seasonal component. Residuals magnitude is 2-3 times more than the Seasonal component. Here's a plot of all the components:

enter image description here

If I understand correctly - the Seasonal component affects the time-series values less than the Residuals. Is this conclusion correct? Does that mean that fluctuations in traffic congestion due to noise are more "meaningful" than the annual pattern?


Edit: Following a suggestion by @brewmaster321, here's the hourly decomposition. I find it hard to interpret, would appreciate any kind of help with this. For example, I would have expected a smoother trend.

enter image description here

I'm adding one example of seasonal period since it's impossible to see on the main plot:

enter image description here

Edit #2: Following another suggestion by @brewmaster321, I used MSTL in order to decompose the different components, but the residuals/seasonality magnitude ratio doesn't seem to change much: enter image description here

Seasonal components look OK when inspected on a smaller scale that allows seeing their periodic nature (each line represents 5 random years/weeks/days):

enter image description here enter image description here enter image description here

I'm just guessing, but is it possible the magnitude of each seasonal component is not larger than residuals' magnitude, but I should actually look at the combined magnitude? This makes sense to me since each data point "contains" these 3 seasonal components. Again, shooting in the dark here and would appreciate any kind of help or guidance.

  • $\begingroup$ A quick look at this and it appears that your hypothesis is correct: fluctuations in congestion due to noise are bigger than your seasonal component. The other possibility is that seasonality is hourly rather than yearly - i.e. what do the plots look like if you use hourly as your period? $\endgroup$ Jan 16 at 8:54
  • $\begingroup$ @brewmaster321 Thanks for the suggestion. I've added it to the question. $\endgroup$
    – Stars
    Jan 16 at 9:24

1 Answer 1


So your traffic data will likely have multiple seasonalities, daily (period = 24), weekly (period = 24*7), and yearly. This is a good use case for MSTL: https://www.statsmodels.org/dev/examples/notebooks/generated/mstl_decomposition.html. If you remove all of these using something like:

   from statsmodels.tsa.seasonal import MSTL
   stl_kwargs = {"seasonal_deg": 0} 
   mstl = MSTL(daily_avg_cong["Vehicles"], periods=(24, 24 * 7, 24*365), 
   res = mstl.fit()

You should end up with lower residuals than the totals of the seasonal components.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.