This project implements a Spatial Convolutional Neural Network (CNN) to forecast urban traffic flow.
It combines grid-based sensor mapping, synthetic/real traffic data, deep learning forecasting, and unsupervised clustering for traffic pattern discovery.
- Convert sensor distance matrix → 2D grid mapping (via MDS)
- Create traffic heatmaps sequences
- Train & tune a 3D CNN with Keras Tuner
- Save best model (
models/cnn_model.keras) - Visualize predicted vs actual heatmaps
- Apply KMeans clustering for unsupervised traffic pattern discovery
- Reduce with PCA for visualization
git clone https://github.com/hariravi-ds/Traffic-Flow-Forecasting-Using-Spatial-CNNs.git
cd Traffic-Flow-Forecasting-Using-Spatial-CNNs
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python main.py
This will: Train + tune CNN
Save best model → models/cnn_model.keras
Save results → results/ folder:
pred_vs_actual.png (forecast comparison)
cluster_centers.png (unsupervised clusters)
pca_clusters.png (PCA scatter of clusters)
See requirements.txt.
Key libraries: TensorFlow / Keras
Keras-Tuner
scikit-learn
numpy, pandas
matplotlib, seaborn
Replace synthetic generator with real-world datasets (e.g. METR-LA, PeMS)
Add spatio-temporal GNNs for comparison
Experiment with attention-based forecasting