Uber Cape Town Road Incidents

Predicting when and where road incidents will occur next in Cape Town. The challenge was not just building a classifier — it was transforming raw geospatial and temporal data into features that capture the rhythm of a city's road network and the conditions under which incidents cluster.

🏆 Rank 13 / 113 successful 711 total competitors Top 11% R

TL;DR: In geospatial incident prediction, the most powerful features are not the static road characteristics — they are the dynamic temporal patterns that capture how a road segment's risk profile changes throughout the day and week. History repeats on roads just as it does in financial markets.

The Problem

Cape Town's road network is complex — a mix of highways, arterial roads, and residential streets, each with different risk profiles at different times of day. The competition asked us to predict which road segments would experience incidents in upcoming time windows.

What made this problem interesting was the sparsity: incidents are rare events distributed across hundreds of road segments and dozens of time slots. A naive model would simply predict "no incident" everywhere and achieve high accuracy while being completely useless for deployment.

The real challenge was engineering features that could distinguish high-risk segment-time combinations from the vast majority of safe ones, using only historical incident data, road characteristics, and Uber Movement travel time patterns.

The Approach

I approached this as a structured classification problem with heavy emphasis on feature engineering. The raw data needed substantial transformation before any model could learn meaningful patterns.

Temporal Feature Engineering

Extracted hour-of-day, day-of-week, month, and holiday indicators. Created rolling incident counts per segment over 7-day, 14-day, and 30-day windows. Peak hours and weekend flags captured the rhythm of when roads become dangerous.

Geospatial Context

Road segment characteristics — length, number of lanes, speed limit, intersection density — served as static risk factors. Segments near highway on-ramps or major intersections carried structurally higher risk regardless of time.

Uber Movement Integration

Travel time data from Uber Movement provided a proxy for congestion. When travel times spike on a segment, the probability of incidents increases. I created congestion ratio features comparing current travel times to free-flow baselines.

Sampling Strategy

With extreme class imbalance, I implemented stratified sampling to ensure the model saw enough positive cases during training. Combined with careful threshold tuning during evaluation, this prevented the model from defaulting to the majority class.

Implementation

The pipeline was built in R with a clear separation of concerns: configuration, data loading, cleaning, feature engineering, train/test construction, sampling, modeling, and evaluation — each in its own script.

XGBoost served as the primary model, with hyperparameters tuned via cross-validation. The feature importance analysis revealed that temporal recurrence features (rolling incident counts) dominated, followed by congestion proxies and road geometry.

The final submission ranked 13th out of 113 successful submissions, placing in the top 11%. Notably, only 113 out of 711 total competitors managed to submit valid predictions, reflecting the difficulty of the problem's data processing requirements.

Key Takeaway

Design insight: In geospatial incident prediction, the most powerful features are not the static road characteristics — they are the dynamic temporal patterns that capture how a road segment's risk profile changes throughout the day and week. History repeats on roads just as it does in financial markets.

Comments

FAQ

What is the key takeaway from "Uber Cape Town Road Incidents"?

In geospatial incident prediction, the most powerful features are not the static road characteristics — they are the dynamic temporal patterns that capture how a road segment's risk profile changes throughout the day and week. History repeats on roads just as it does in financial markets.

Who wrote this and what is it about?

This was written by Mahmoud Trigui, Senior Data Scientist. Predicting when and where road incidents will occur in Cape Town. Multi-source geospatial feature engineering, temporal pattern extraction, and XGBoost ensemble. Ranked 13th out of 113 successful submissions (711 total competitors). Zindi, January 2020.

Machine Learning Feature Engineering MLForecast Time Series Decomposition Forecasting LightGBM XGBoost Catboost Clustering Segmentation NLP LLMs Web App R Markdown SQL Oracle DB SAS-Guide SAS E-Miner Dataiku BigQuery GCP Python R CRISP-DM Hypothesis Testing ANOVA Data Analytics Dimensionality Reduction Recommendation System Network Analysis Geospace Analysis Spatial Data Embedding Sampling Techniques Decision Rules Data Storytelling CVM Churn Fraud Detection Sentiment Analysis Topic Modeling IBM Watson PowerBI Looker Studio VBA Statistical Learning Ensemble Modeling Stacking Cross-Validation Profiling ABT Construction Plumber Tidyverse Shiny Prophet Deep Learning Scikit-Learn JSON SAS Programming Git VS Code CSS Styling Automated Reporting Outlier Detection Temporal Clustering Startup Survival Pre-Valuation Modeling K-Means Decision Trees Data Science Predictive Modeling SVM LDA Text Classification Weight Prediction Pattern Recognition Real-Time Detection Community Detection Pipeline Automation Data Quality Checks Data Reliability Specification Mapping Business Strategy Marketing Campaigns Try & Buy Frameworks KPI Dashboards Network Quality Sales Analytics Mentoring Statistics Lecturer Remote Work Hybrid Work Consulting Contract Full-Time Freelance Sofrecom Orange Group Tunisia Telecom Kiota Intelligence VC Analytics Series A Prediction Production ML Applied AI Prompt Engineering Business Forecasting Decision Systems Graph Analytics Household Detection Multi-SIM Detection FTTH Forecasting Audit Extraction Infrastructure Classification Pydantic GPT-4 OpenAI API Base64 Classification Zindi Codementor LAAS-CNRS ESSAI MIT xPRO Tunisia ML Competition Cell Tower Analysis Uber Logistics Uber Cape Town Necessary Condition Analysis Behavioral Signals Spike Smoothing Observation Unit Design Dendrogram Ward Clustering VIF Target Encoding Machine Learning Feature Engineering MLForecast Time Series Decomposition Forecasting LightGBM XGBoost Catboost Clustering Segmentation NLP LLMs Web App R Markdown SQL Oracle DB SAS-Guide SAS E-Miner Dataiku BigQuery GCP Python R CRISP-DM Hypothesis Testing ANOVA Data Analytics Dimensionality Reduction Recommendation System Network Analysis Geospace Analysis Spatial Data Embedding Sampling Techniques Decision Rules Data Storytelling CVM Churn Fraud Detection Sentiment Analysis Topic Modeling IBM Watson PowerBI Looker Studio VBA Statistical Learning Ensemble Modeling Stacking Cross-Validation Profiling ABT Construction Plumber Tidyverse Shiny Prophet Deep Learning Scikit-Learn JSON SAS Programming Git VS Code CSS Styling Automated Reporting Outlier Detection Temporal Clustering Startup Survival Pre-Valuation Modeling K-Means Decision Trees Data Science Predictive Modeling SVM LDA Text Classification Weight Prediction Pattern Recognition Real-Time Detection Community Detection Pipeline Automation Data Quality Checks Data Reliability Specification Mapping Business Strategy Marketing Campaigns Try & Buy Frameworks KPI Dashboards Network Quality Sales Analytics Mentoring Statistics Lecturer Remote Work Hybrid Work Consulting Contract Full-Time Freelance Sofrecom Orange Group Tunisia Telecom Kiota Intelligence VC Analytics Series A Prediction Production ML Applied AI Prompt Engineering Business Forecasting Decision Systems Graph Analytics Household Detection Multi-SIM Detection FTTH Forecasting Audit Extraction Infrastructure Classification Pydantic GPT-4 OpenAI API Base64 Classification Zindi Codementor LAAS-CNRS ESSAI MIT xPRO Tunisia ML Competition Cell Tower Analysis Uber Logistics Uber Cape Town Necessary Condition Analysis Behavioral Signals Spike Smoothing Observation Unit Design Dendrogram Ward Clustering VIF Target Encoding