DEV Community

jpetoskey
jpetoskey

Posted on • Updated on

Time Series Decomposition - Spotting Seasonality

The results fascinated me -- seasonal patterns when none were visible in the raw data.

I had looked at trends in this visualization of the median price of homes by zip code: median price of homes

And, mainly noticed the upward and downward trend in the median price.

However, when I performed and plotted a seasonal decomposition with statsmodels.tsa.seasonal:

# Import and apply seasonal_decompose()
from statsmodels.tsa.seasonal import seasonal_decompose
decomposition = seasonal_decompose(np.log(percent1))

# Gather the trend, seasonality, and residuals 
trend = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid

# Plot gathered statistics
plt.figure(figsize=(12,8))
plt.subplot(411)
plt.plot(np.log(m1), label='Original', color='blue')
plt.legend(loc='best')
plt.subplot(412)
plt.plot(trend, label='Trend', color='blue')
plt.legend(loc='best')
plt.subplot(413)
plt.plot(seasonal,label='Seasonality', color='blue')
plt.legend(loc='best')
plt.subplot(414)
plt.plot(residual, label='Residuals', color='blue')
plt.legend(loc='best')
plt.tight_layout()
Enter fullscreen mode Exit fullscreen mode

I noticed something surprising in the seasonality output - seasonality!

seasonality! :)

I enjoyed seeing the seasonal pattern. I had always heard that prices were slightly higher in the spring/summer months, but it is confirming to see it in the decomposition.

I am now wondering about the magnitude of the trend. I know the magnitude can't be too large, but I'm not sure how large.

I am curious about how I would figure this out.

So far I have tried reversing the log transformation that was part of the process of decomposing the original data, but then I am left with a result of 1, as the magnitude of the seasonal trend oscillates between -0.001 and 0.0005. I'm guessing the seasonal difference is greater than $1 in the real estate market with median prices varying in the data for this zip code between $120,000 and $700,000.

If anyone reads this and has answers, please message me or comment - Jim.Petoskey.146@gmail.com.

Top comments (0)