Skip to content

Repository files navigation

🌦️ Weather Prediction using Linear Regression

This project predicts temperature, humidity, and pressure using historical weather data from European cities (2000-2010) through linear regression modeling. Developed in Jupyter Notebook for the Artificial Intelligence course.

📌 Project Overview

Predicts three key meteorological variables for Basel:

  • Temperature (°C)
  • Humidity (stored as a fraction in the raw data; reported as %)
  • Pressure (stored in bar in the raw data; reported as hPa)

Using machine learning (Linear Regression) on a dataset covering 18 European cities.

👨‍💻 Developer

'Affan Najiy Bin Rusdi
Student ID: 22010453
University: Universiti Teknologi PETRONAS

📂 Dataset

Source: Zenodo Weather Prediction Dataset
Features:

  • Daily meteorological records (2000-2010)
  • 18 European cities
  • Multiple weather parameters

🔧 Technical Implementation

🛠️ Tech Stack

  • Python 3
  • Libraries:
    • pandas (data handling)
    • numpy (numerical operations)
    • matplotlib/seaborn (visualization)
    • scikit-learn (machine learning)

📊 Methodology

Data Preprocessing

  • Physical plausibility check — rejects impossible sensor readings (e.g. negative air pressure) that dropna() cannot catch
  • Missing value handling
  • Drop raw DATE column (kept MONTH for seasonal signal)
  • Correlation analysis

Modeling

  • Separate Linear Regression models for temperature, humidity and pressure
  • Chronological 80/20 split (train 2000–2008, test 2008–2010) — avoids letting the model learn from the future to predict the past
  • No target leakage: each model is blind to the other two targets for the same day
  • Two framings compared: same-day estimation vs. genuine next-day forecasting

Evaluation Metrics

  • Mean Absolute Error (MAE), reported in real units (°C, %, hPa)
  • Mean Squared Error (MSE)
  • R² Score
  • Compared against two baselines: seasonal average, and persistence ("tomorrow = today")

🔍 Key Findings

  • Four corrupted rows out of 3,654 (negative and near-vacuum pressure readings) were enough to push several models to negative R², i.e. worse than guessing the average. Removing them lifted next-day pressure R² from −9.24 to 0.82.
  • Same-day estimation is near-perfect (temperature R² 0.996, off by 0.38 °C) because regional weather moves as one system — but this is reconstruction, not forecasting.
  • Genuine next-day forecasting is far harder: temperature error more than triples to 1.30 °C, though it still beats persistence by 21%.
  • Humidity is consistently the hardest target, being driven by local effects rather than regional patterns.

📋 Code Structure

1.  Data Loading & Inspection
2.  Missing Value Analysis
3.  Data Cleaning (incl. physical plausibility check)
4.  Feature Selection
5.  Chronological Train-Test Split
6.  Model Training
7.  Evaluation (MAE / MSE / R²)
8.  Visualisation
9.  Baseline Comparison
10. Next-Day Forecasting
11. Feature Influence Analysis
12. Error Breakdown by Month
13. Conclusions

🌐 Live Site

A plain-language walkthrough of the whole analysis is published via GitHub Pages, rebuilt automatically from the notebook on every push.

🚀 Getting Started

Install requirements:

pip install pandas numpy matplotlib seaborn scikit-learn

Run Jupyter Notebook:

jupyter notebook weather_predict.ipynb

📚 Term Definitions

  • MSE: Measures average squared difference between predicted and actual values
  • R² Score: Indicates proportion of variance explained by the model
  • Correlation: Statistical relationship between variables (-1 to 1)

📜 License

Educational use only - Not for commercial purposes

🙏 Acknowledgements

Thank you for reading!

About

Predicts weather using ML models trained on historical climate data

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages