Skip to content

Nora-design/ANN-Experiment

Repository files navigation

ANN Weather Forecasting for Ankara

This project implements a monthly maximum temperature forecasting system using Artificial Neural Networks. The task is to predict the next 12 monthly tmax values for Ankara, Turkey using the previous 36 months of meteorological observations.

The project was developed for the AID404 Assignment 2 ANN weather forecasting task.

Project Overview

The forecasting problem is formulated as a multivariate, multi-step time-series prediction task.

  • Target variable: tmax
  • Lookback window: 36 months
  • Forecast horizon: 12 months
  • Dataset location: Ankara, Turkey
  • Data source: NASA POWER monthly meteorological data
  • Main model: Feed-forward MLP
  • Evaluation metrics: MAE, RMSE, sMAPE, Skill Score

The project compares simple baseline models with several neural network approaches:

  1. Persistence baseline
  2. Seasonal naive baseline
  3. MLP with all features
  4. MLP with selected features
  5. MLP with extreme-aware loss
  6. Hybrid selected/extreme MLP model

Project Structure

ANN-Experiment/
|
|-- data/
|   |-- turkey_weather_ankara_monthly.csv
|
|-- models/
|   |-- mlp.py
|   |-- variant.py
|
|-- outputs/
|   |-- figures/
|   |   |-- forecast_MLP_All_Features.png
|   |   |-- forecast_MLP_Selected_Features.png
|   |   |-- forecast_MLP_Extreme_Aware_Loss.png
|   |   |-- loss_MLP_All_Features.png
|   |   |-- loss_MLP_Selected_Features.png
|   |   |-- loss_MLP_Extreme_Aware_Loss.png
|   |
|   |-- results/
|       |-- correlation_ranking.csv
|       |-- mutual_information_ranking.csv
|       |-- final_results.csv
|       |-- extreme_only_results.csv
|       |-- history_MLP_All_Features.json
|       |-- history_MLP_Selected_Features.json
|       |-- history_MLP_Extreme_Aware_Loss.json
|
|-- baselines.py
|-- dataset.py
|-- dataset_fetch.py
|-- evaluate.py
|-- feature_selection.py
|-- main.py
|-- train.py
|-- utils.py
|-- README.md
|-- requirements.txt

Dataset

The dataset is downloaded using dataset_fetch.py from the NASA POWER API.

The downloaded variables are mapped as follows:

NASA POWER Variable Project Column Description
T2M_MAX tmax Monthly maximum temperature
T2M_MIN tmin Monthly minimum temperature
T2M temp Monthly mean temperature
PRECTOTCORR prcp Monthly precipitation
PS pres Monthly surface pressure

Additional calendar features are added:

Feature Description
month_sin Sine encoding of month
month_cos Cosine encoding of month

These features help the model represent yearly seasonality.

Forecasting Setup

Each sample is created using a sliding window approach.

Input:
36 months of historical weather features

Output:
Next 12 months of tmax values

For example, if 7 features are used:

Input size = 36 x 7 = 252
Output size = 12

Since the model is an MLP, the 36-month input matrix is flattened into a single vector before being passed into the network.

Models

Persistence Baseline

The persistence baseline predicts all future months using the last observed tmax value.

Seasonal Naive Baseline

The seasonal naive baseline predicts the next 12 months using the previous 12 months of tmax.

MLP All Features

This model uses all available input features:

tmax, tmin, prcp, temp, pres, month_sin, month_cos

MLP Selected Features

This model removes pres after feature selection analysis.

Selected features:

tmax, tmin, prcp, temp, month_sin, month_cos

Feature selection was performed using:

  1. Correlation-based ranking
  2. Mutual information ranking

Extreme-Aware Loss Model

The extreme-aware model uses a weighted MSE loss. Extreme hot months are defined as the top 10 percent of training tmax values.

In this experiment:

Extreme threshold: tmax >= 35.55
Scaled threshold: 1.218
Extreme weight: 3.0

Errors on extreme hot months receive a larger penalty during training.

Hybrid Selected/Extreme Model

The hybrid model combines two trained models:

  • Default model: selected-feature MLP
  • Extreme model: extreme-aware MLP

The hybrid switches to the extreme-aware prediction when either model predicts an extreme hot value. This decision is based only on predictions, not on true future values.

Results

Overall Test Results

Model MAE RMSE sMAPE Skill
Persistence 11.100 13.296 45.499 0.000
Seasonal Naive 7.883 10.740 32.987 0.192
MLP All Features 2.681 3.145 13.327 0.763
MLP Selected Features 2.441 2.899 11.537 0.782
MLP Extreme-Aware Loss 2.441 2.942 11.992 0.779
MLP Hybrid Selected/Extreme 2.359 2.805 11.304 0.789

The best overall model is the hybrid selected/extreme model.

Extreme-Hot-Month Results

Model Extreme MAE Extreme RMSE Extreme sMAPE Extreme Skill N
MLP Selected Features 3.094 3.490 8.360 0.782 72
MLP Extreme-Aware Loss 2.298 2.743 6.131 0.828 72
MLP Hybrid Selected/Extreme 2.357 2.829 6.306 0.823 72

The extreme-aware loss model performs best on extreme hot months. The hybrid model achieves the best overall balance between general accuracy and extreme-temperature handling.

Installation

This project can be run with uv.

uv sync

If you are not using uv, install the required packages manually:

pip install -r requirements.txt

Required main packages:

  • numpy
  • pandas
  • torch
  • scikit-learn
  • matplotlib
  • requests

How to Run

1. Download the dataset

uv run dataset_fetch.py

This creates:

data/turkey_weather_ankara_monthly.csv

2. Run all experiments

uv run main.py

This trains all models and creates result files under:

outputs/results/
outputs/figures/

Output Files

Results

File Description
final_results.csv Overall model comparison
extreme_only_results.csv Extreme-hot-month comparison
correlation_ranking.csv Correlation-based feature ranking
mutual_information_ranking.csv Mutual information feature ranking
history_MLP_All_Features.json Training history for all-feature MLP
history_MLP_Selected_Features.json Training history for selected-feature MLP
history_MLP_Extreme_Aware_Loss.json Training history for extreme-aware MLP

Figures

File Description
loss_MLP_All_Features.png Training and validation loss for all-feature MLP
loss_MLP_Selected_Features.png Training and validation loss for selected-feature MLP
loss_MLP_Extreme_Aware_Loss.png Training and validation loss for extreme-aware MLP
forecast_MLP_All_Features.png Example forecast for all-feature MLP
forecast_MLP_Selected_Features.png Example forecast for selected-feature MLP
forecast_MLP_Extreme_Aware_Loss.png Example forecast for extreme-aware MLP

Main Findings

The neural network models significantly outperform the persistence and seasonal naive baselines. Feature selection improves generalization by removing surface pressure, which had weak importance according to both correlation and mutual information analysis.

The extreme-aware loss improves prediction performance on extreme hot months, but it does not achieve the best overall test performance by itself. The hybrid selected/extreme model achieves the best overall performance by using the selected-feature MLP for normal predictions and the extreme-aware MLP when an extreme hot value is predicted.

Notes

  • The model uses chronological train, validation, and test splits.
  • No shuffling is applied before splitting.
  • Standardization is fitted only on the training set.
  • Final MAE and RMSE values are reported in the original temperature scale.
  • The hybrid model uses prediction-based switching only. It does not use true future values for selecting predictions.

About

AID404 2nd Assignment Project

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages