- Practical Time Series Analysis
- Dr. Avishek Pal Dr. PKS Prakash
- 308字
- 2021-07-08 10:18:26
Seasonal sub series plot
For a known periodicity of seasonal variations, seasonal sub series redraws the original series over batches of successive time periods. For example, the periodicity in the CO2 concentrations is 12 months and based on this a seasonal sub series plots on mean and standard deviation of the residuals are shown in the following figure. To visualize seasonality in the residuals, we create quarterly mean and standard deviations.
A seasonal sub series reveals two properties:
- Variations within seasons as within a batch of successive months
- Variations between seasons as between batches of successive months


Let us now describe the code used for generating the preceding plots. First, we need to add the residuals and quarter labels to the CO2 concentrations DataFrame. This is done as follows:
data['Residuals'] = residuals month_quarter_map = {1: 'Q1', 2: 'Q1', 3: 'Q1', 4: 'Q2', 5: 'Q2', 6: 'Q2', 7: 'Q3', 8: 'Q3', 9: 'Q3', 10: 'Q4', 11: 'Q4', 12: 'Q4' } data['Quarter'] = data['Month'].map(lambda m: month_quarter_map.get(m))
Next, the seasonal mean and standard deviations are computed by grouping by the data over Year and Quarter:
seasonal_sub_series_data = data.groupby(by=['Year', 'Quarter'])['Residuals']\ .aggregate([np.mean, np.std])
This creates the new DataFrame as seasonal_sub_series_data, which has quarterly mean and standard deviations over the years. These columns are renamed as follows:
seasonal_sub_series_data.columns = ['Quarterly Mean', 'Quarterly Standard Deviation']
Next, the quarterly mean and standard deviations are plotted by running the following lines of code:
#plot quarterly mean of residuals
plt.figure(figsize=(5.5, 5.5))
seasonal_sub_series_data['Quarterly Mean'].plot(color='b')
plt.title('Quarterly Mean of Residuals')
plt.xlabel('Time')
plt.ylabel('CO2 concentratition')
plt.xticks(rotation=30)
#plot quarterly standard deviation of residuals
plt.figure(figsize=(5.5, 5.5))
seasonal_sub_series_data['Quarterly Standard Deviation'].plot(color='b')
plt.title('Quarterly Standard Deviation of Residuals')
plt.xlabel('Time')
plt.ylabel('CO2 concentratition')
plt.xticks(rotation=30)
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- 簡單高效LATEX
- PostgreSQL Cookbook
- PostgreSQL技術內幕:事務處理深度探索
- 營銷數據科學:用R和Python進行預測分析的建模技術
- Hands-On Microservices with Kotlin
- 自然語言處理Python進階
- MongoDB,Express,Angular,and Node.js Fundamentals
- Lighttpd源碼分析
- Building Dynamics CRM 2015 Dashboards with Power BI
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- Learning Unreal Engine Game Development
- Python 快速入門(第3版)
- INSTANT LESS CSS Preprocessor How-to
- Python Penetration Testing Essentials