AI-powered urban traffic congestion prediction system for Nairobi, Kenya
# UTCPS β Urban Traffic Congestion Prediction System
### Nairobi, Kenya π°πͺ
An AI-powered platform that forecasts traffic congestion levels
(Low, Medium, High) at least 30 minutes in advance across
12 key Nairobi road segments.
## Features
- Real-time traffic data via TomTom Traffic API
- LSTM/GRU model (TensorFlow) β Test RMSE: 0.1378
- GNN model (PyTorch) β Test RMSE: 0.2081
- Anomaly detection (accidents, road closures)
- Interactive Streamlit dashboard with Nairobi map
- REST API with 9 endpoints (FastAPI)
- Weather impact analysis (OpenWeatherMap)
- Docker containerization
## Tech Stack
Python 3.11 | TensorFlow 2.15 | PyTorch 2.2 | Apache Kafka |
Streamlit | FastAPI | Docker | SQLite
## Setup
### 1. Clone the repository
git clone
github.com
cd UTCPS-Nairobi
### 2. Create virtual environment (Python 3.11 required)
py -3.11 -m venv .venv
.venv\Scripts\activate
### 3. Install dependencies
pip install -r requirements.txt
### 4. Configure API keys
Create a .env file in the project root:
TOMTOM_API_KEY=your_key_here
OPENWEATHER_API_KEY=your_key_here
### 5. Download dataset
Download metr-la.h5 from:
drive.google.com
Save to: data/raw/metr-la.h5
### 6. Preprocess and train
python src/preprocessing/preprocess.py
python src/models/lstm_model.py
python src/models/gnn_model.py
### 7. Run the system
# Terminal 1 - Dashboard
streamlit run src/dashboard/app.py
# Terminal 2 - API
uvicorn src.api.api_server:app --reload --port 8000
## Dashboard Login
- Admin: admin / utcps2024
- Planner: planner / nairobi24
## Project Structure
UTCPS/
βββ src/
β βββ ingestion/ # Nairobi roads, TomTom fetcher, Kafka
β βββ preprocessing/ # METR-LA processing, feature engineering
β βββ models/ # LSTM, GNN, anomaly detector, logger
β βββ api/ # FastAPI REST endpoints
β βββ dashboard/ # Streamlit app, analytics page
βββ config/
β βββ config.yaml β¦