Excellent forecasting performance was achieved:
- MAE (°C): 1.29
- RMSE (°C): 2.66
This excellent performance is primarily attributed to the careful preprocessing of the data, particularly the weekly grouping. Aggregating high-frequency weather data into weekly averages significantly minimized the influence of short-term noise and irregularities, thereby enabling the Unobserved Components Model (UCM) to more accurately capture the underlying trend, seasonal, and cyclic patterns.
Below are the key outputs of the modeling process. All visualizations are based on smoothed states extracted from the fitted Unobserved Components Model (UCM).

Forecasted weekly mean temperatures with 95% confidence interval. The blue line represents the predicted values; the shaded area denotes the uncertainty range. Historical data (train/test) is shown for reference.

The estimated level (baseline) of the temperature series, evolving over time. Captures long-term shifts independent of seasonality or cycles.

The estimated seasonal pattern with a period of 52 weeks, reflecting recurring annual dynamics. The stochastic nature allows it to adapt to small inter-annual shifts.

A dynamic trend component showing the evolution of the rate of change in the temperature level. Useful for identifying periods of acceleration or stabilization in temperature trends.
The analysis applies a structural time series modeling approach using the Unobserved Components Model (UCM) to forecast weekly aggregated temperatures. Key methodological steps include:
-
Weekly Aggregation:
Aggregating the data on a weekly basis effectively reduces high-frequency noise, allowing the model to focus on more stable and interpretable long-term patterns. This step was instrumental in achieving the reported high performance (MAE: 1.29 °C, RMSE: 2.66 °C). -
Model Configuration:
The UCM is parameterized with:- A local linear trend to capture both the level and the rate of change.
- A seasonal component with a period of 52 weeks, reflecting the annual cycle present in the data.
- Stochastic seasonal and stochastic cyclic components that allow these effects to vary over time, thereby increasing the model's flexibility and adaptability to real-world data.
-
Forecasting and Evaluation:
A 52-week forecast is produced and evaluated using standard error metrics, providing a robust assessment of model performance.
The temperature data is sourced from Open-Meteo, which offers free access to weather forecast information.
License: The data is distributed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). For more details on the licensing terms, please refer to Open-Meteo's license page.
-
Clone the Repository:
git clone https://github.com/yourusername/WeatherForecasting_UCM.git
cd WeatherForecasting_UCM -
Launch the Jupyter Notebook:
Open the
WeatherForecasting_UCM.ipynbnotebook using Jupyter Notebook or JupyterLab. -
Run the Notebook Cells Sequentially:
Execute the cells in order to:
- Load and preprocess the temperature data.
- Aggregate the data to weekly averages.
- Fit the UCM and generate a 52-week forecast.
- Evaluate the forecasting performance.
- Extract and visualize key model components.
-
Review the Visualizations:
Interactive visualizations are generated within the notebook, and static representations are available as image files: Forecast.png, Level.png, Seasonal.png, and Trend.png.
This repository is distributed under the MIT License.
For questions, suggestions, or contributions, please open an issue or submit a pull request.