Nairobi Ambulance Deployment Optimization

This competition is hosted on Zindi, a machine learning platform for data science challenges.

TL;DR: Prediction and decision are different problems. A perfect probability model is only useful if its output can be converted into the actual action that needs to be taken. Design the full pipeline — from raw data to final decision — before optimizing any single component.

The Problem

This wasn't a prediction problem — it was a decision problem. The model predicts crash probability, but the real output is: where should 6 ambulances sit right now? Every 3 hours, across all of Nairobi, I needed to position 6 ambulances to minimize their distance to crashes that haven't happened yet. Training data covered 6,318 crashes from January 2018 to June 2019; the test period was July to December 2019.

The fundamental challenge is the gap between prediction and action. Even a perfect crash probability model doesn't directly tell you where to put ambulances. Six ambulances can't cover the entire city — they need to be distributed across predicted hotspots in a way that minimizes worst-case response distance. This requires converting a continuous probability surface into exactly 6 discrete locations.

An additional complexity: most of the road survey features (228 columns) were obfuscated — column names were anonymized, making it impossible to interpret individual features. And weather data only existed for the training period, meaning I needed to simulate weather for the test months without using future information.

🏆
Rank 13 out of 113 competitors

My Approach

I designed a two-stage system. Stage 1 predicts where crashes will happen: binary classification at the road-segment × 3-hour-window level, answering "will a crash occur on this segment during this time window?" Stage 2 converts those predictions into ambulance positions: cluster the top predicted hotspots into 6 groups and place ambulances at the cluster centroids.

The key insight was decomposing the city into approximately 800 road segments. Rather than predicting at individual latitude/longitude points (which creates an impossibly sparse target), each segment becomes a row in the analytical base table, crossed with every 3-hour time window. This converts a spatial problem into structured tabular classification — my home territory.

For features, I fused five data sources per segment per time window: crash history (segment frequency, monthly elasticity, seasonal patterns), road survey data (228 obfuscated features reduced to 2 dimensions via t-SNE), Uber Movement speeds per road segment per hour, simulated weather, and temporal features (hour bin, weekend, holidays). The t-SNE reduction was crucial — with 228 unnamed columns, I couldn't select features based on meaning. But t-SNE captured the latent structure of road characteristics without needing to know what the columns represent.

For weather in the test period, I used year-over-year monthly adjustment: July 2019 weather was estimated as July 2018 weather multiplied by the recent trend ratio. This preserves seasonal patterns without using future data. For the extreme class imbalance (about 0.1% positive rate), I used stratified downsampling of negatives with multiple subsets at different ratios feeding into the ensemble.

Key Decisions

Segment-Level ABT Instead of Point-Level

Decomposing the city into ~800 road segments and crossing with time windows converts an impossible spatial prediction task into manageable tabular classification. Each segment accumulates enough history to learn from, while point-level data would be too sparse.

t-SNE for 228 Obfuscated Road Features

When you can't interpret columns, you can't do feature selection by meaning. t-SNE (after NZV and correlation filtering) captures the latent structure of road characteristics in 2 dimensions — crosswalks, obstacles, traffic patterns — without needing column semantics.

Crash Elasticity as Temporal Signal

Raw crash counts are always zero for the test period. But month-over-month change rates per segment capture the trend — segments with accelerating crash rates get higher predicted probabilities even without future crash data.

Prediction-to-Deployment via K-Means Clustering

Taking the top-50 segments by predicted probability and clustering their midpoints into 6 groups ensures ambulances are distributed across hotspots rather than concentrated at a single high-risk point. The output is 6 coordinates per time window — exactly what the competition requires.

Key Takeaway

This project taught me the difference between prediction problems and decision problems. A perfect predictive model is only half the system — converting predictions into actionable decisions (6 ambulance locations) requires a separate optimization layer. The two stages must be designed together: the prediction model's output format must be compatible with what the decision layer needs as input. Thinking about the full system from the start — not just the model — is what separates data science from machine learning.

Design insight: Prediction and decision are different problems. A perfect probability model is only useful if its output can be converted into the actual action that needs to be taken. Design the full pipeline — from raw data to final decision — before optimizing any single component.

FAQ

What is the key takeaway from "Nairobi Ambulance Deployment"?

Prediction and decision are different problems. A perfect probability model is only useful if its output can be converted into the actual action that needs to be taken. Design the full pipeline — from raw data to final decision — before optimizing any single component.

Who wrote this and what is it about?

This was written by Mahmoud Trigui, Senior Data Scientist. Optimizing ambulance placement in Nairobi using risk prediction, geographic clustering, and centroid-based deployment. Ranked Top 31% (331/1003 competitors) on Zindi, January 2021.

Comments

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