An end-to-end machine learning project that predicts public transport delays and provides personalized commute recommendations using live weather and event data.
Potential applications include:
- Smart commuting assistants
- Transit planning tools
- Traffic management systems
- Journey recommendation platforms
- Built an end-to-end transit delay prediction pipeline using SQLite, machine learning, SHAP, and external APIs.
- Evaluated 3 regression models and 6 classification strategies.
- Integrated live weather (OpenWeatherMap) and event (Ticketmaster) APIs into a recommendation engine.
- Used SHAP explainability to identify the strongest drivers of transit delays and commute risk.
- Developed an interactive application that predicts delay, estimates commute risk, and recommends departure times.
Kaggle Dataset
↓
SQL Database (SQLite)
↓
Exploratory Data Analysis
↓
Feature Engineering
↓
Regression + Classification Models
↓
SHAP Explainability
↓
Interactive CLI Application
↓
Live Weather & Event APIs
| Phase | Description |
|---|---|
| 1 | Data collection & SQL database setup |
| 2 | Data quality check |
| 3 | Exploratory Data Analysis (EDA) |
| 4 | Feature Engineering |
| 5 | Machine Learning Modeling |
| 6 | Model Explainability (SHAP) |
| 7 | Interactive CLI app with live weather & events APIs |
- Python
- Pandas
- NumPy
- Scikit-Learn
- XGBoost
- SHAP
- Matplotlib / Seaborn
- SQLite
- imbalanced-learn (SMOTE)
- OpenWeatherMap API
- Ticketmaster API
├── transport_delay_model.ipynb ← Main notebook: Phase 1–6 (EDA → SHAP)
├── transport_delay_app.ipynb ← Phase 7: App code walkthrough
├── transport_delay_app.py ← Interactive CLI app (run from Terminal)
├── .env.example ← API key template (copy to .env)
├── .gitignore
└── README.md
Note:
public_transport_delays.csvandtransport_features.csvare excluded from this repo via.gitignore. Download the dataset from Kaggle (see Setup below) and run the notebook to generatetransport_features.csv.
git clone https://github.com/tracychanty/smart-commute-prediction-recommendation-system.git
cd smart-commute-recommendation-systempip install pandas numpy matplotlib seaborn scikit-learn xgboost lightgbm \
shap imbalanced-learn python-dotenv requestsDownload the Public Transport Delays with Weather and Events dataset from
Kaggle and place public_transport_delays.csv
in the project root.
cp .env.example .envEdit .env and add your free API keys:
- OpenWeatherMap: openweathermap.org/api
- Ticketmaster: developer.ticketmaster.com
Open transport_delay_model.ipynb in Jupyter or VS Code and run all cells.
This covers Phase 1–6 and generates transport_features.csv.
python transport_delay_app.py| Hypothesis | Outcome | |
|---|---|---|
| H1 | Weather conditions (rain, snow, storm) are the strongest predictors of transit delay | ❌ Rejected — SHAP analysis showed time and seasonal features were stronger predictors |
| H2 | Time-based factors (peak hour, time of day, day of week) compound delay when combined with adverse weather or nearby events | |
| H3 | Public events (protests, parades, concerts) increase delay beyond the baseline, with larger and more disruptive events having greater impact. | |
| H4 | ML model trained on weather, time, and event features can predict delay magnitude and classify commute risk |
| Model | RMSE | R² |
|---|---|---|
| Linear Regression | 9.33 min | -0.034 |
| Random Forest | 9.37 min | -0.042 |
| XGBoost | 9.83 min | -0.146 |
| Mean-prediction baseline | 9.18 min | 0.000 |
Despite testing Linear Regression, Random Forest, and XGBoost, all models achieved negative R² scores. This indicates that the available features contain limited predictive signal for exact delay magnitude.
This finding itself is valuable, as it demonstrates a complete machine learning workflow, rigorous model evaluation, hypothesis testing, and transparent reporting rather than presenting artificially inflated results. The results suggest that richer operational data such as GPS tracking, passenger volume, service disruptions, and real-time traffic information would be required for accurate delay forecasting.
| Strategy | F1 | Accuracy |
|---|---|---|
| S3: Fixed bins + SMOTE + Random Forest | 0.379 | 0.380 |
| S2: Quantile bins + Logistic Regression | 0.374 | 0.367 |
| S1: Baseline (no correction) | 0.337 | 0.337 |
Six strategies were tested across two model families (Logistic Regression and Random Forest), varying binning approach, SMOTE oversampling, and class weighting.
- Regression:
time_of_day,season_Summer, andhour_sinare the top features — time and seasonal structure drive predictions more than weather - Classification:
humidity_percent,transport_type_enc, andhas_eventdominate High-risk predictions - All SHAP contributions are below ±1.5 min, confirming no single feature pushes predictions far from the base value — consistent with weak correlations
Run python transport_delay_app.py from Terminal. The app asks:
- Destination
- Desired arrival time
- Transport type (Bus / Metro / Train / Tram)
- Route (filtered to your chosen transport type)
- Origin & destination station
- Scheduled travel duration
- Traffic congestion level
- Is today a holiday?
Then fetches live weather (OpenWeatherMap) and live events (Ticketmaster), runs the trained models, and outputs:
🚌 TRIP RECOMMENDATION RESULT
───────────────────────────────────────────────────────
Destination : University of Toronto
Arrival time : 09:00 | Transport: Metro
───────────────────────────────────────────────────────
Predicted Delay : 13.5 min
Commute Risk : Medium 🟡
⏰ Recommended departure : 08:24
───────────────────────────────────────────────────────
💡 RECOMMENDATION
🟡 Moderate delay expected. Consider leaving a
few minutes earlier or using a faster route.
───────────────────────────────────────────────────────
- Dataset uses synthetic station names and route IDs — destination input is used for display only and does not affect model predictions
- A temporal train/test split (first 70% of dates → train) would be more rigorous for production use than the random split used here
- With ~2,000 rows and weak feature signal, model performance is modest. Real-world improvement would require richer data (GPS tracking, passenger load, incident logs)
MIT





