# CO2 Emission Forecasting & Optimization – Morocco
## Overview
This project predicts, analyzes, and optimizes CO2 emissions for Morocco using historical data, machine learning, and mathematical optimization. It includes an interactive dashboard to simulate sector-specific emission reductions and estimate their real-time impact on total CO2 emissions.
The project was built on the Our World in Data – Carbon Emissions dataset (~1.4 GB), filtered down to Morocco-specific records saved as `morocco_data.csv`.
---
## Project Structure
```
├── notebook.ipynb # Full analysis pipeline (EDA → Forecast → ML → Optimization)
├── dashboard.py # Interactive Dash app for scenario simulation
├── morocco_data.csv # Filtered dataset for Morocco (pivoted, ready to use)
├── output.png # CO2 emissions over time plot
├── output2.png # Sector-wise base vs optimized emissions plot
└── data/ # Raw global dataset (~1.4 GB) — not tracked in Git
```
---
## Dataset
- **Source:** Our World in Data – Carbon Emissions
- **Raw size:** ~1.4 GB (global, all countries)
- **Filtered to:** Morocco only → saved as `morocco_data.csv`
**Features used:**
| Column | Description |
|--------|-------------|
| `year` | Year of observation |
| `co2` | Total CO2 emissions (million tonnes) |
| `coal_co2` | CO2 from coal (million tonnes) |
| `oil_co2` | CO2 from oil (million tonnes) |
| `gas_co2` | CO2 from gas (million tonnes) |
| `gdp` | GDP in international-$ (2011 prices) |
| `population` | Country population |
| Primary energy consumption | Measured in terawatt-hours |
---
## Pipeline
### 1. Data Filtering & Pivoting
- Loaded the global OWID dataset and filtered rows for **Morocco**.
- Selected 7 relevant indicators (CO2 total, coal, oil, gas, GDP, population, energy).
- Pivoted from long format → wide format (rows = years, columns = indicators).
- Dropped rows with missing values and cast all columns to float.
### 2. Explorat …