Sendy Logistics — Delivery Time Prediction

Predicting delivery duration (pickup to arrival) for a logistics platform in Nairobi, Kenya.

TL;DR: When a domain formula exists, don't compete with it — augment it. Feed the analytical estimate as a feature and let the ML model learn the residual. This combines structural domain knowledge with contextual pattern recognition for better predictions than either approach alone.

The Problem

Predicting delivery duration in Nairobi sounds straightforward until you realize how many factors a simple formula misses. A motorcycle courier picking up a package has a known origin, a known destination, and a calculable distance. You could estimate duration as distance divided by average speed. But Nairobi traffic is wildly variable. Rider experience matters. Pickup delays matter. The time of day, the neighborhood, and the day of week all interact in ways that a formula cannot capture.

The competition provided historical delivery records from Sendy, a logistics platform, with timestamps for placement, confirmation, pickup, and arrival. The goal was to predict the total duration from pickup to arrival. The evaluation metric was RMSE, meaning large errors are penalized disproportionately — getting a few deliveries very wrong hurts more than being slightly off on many.

The interesting tension in this problem is between the physics baseline (distance/speed) and the contextual complexity (traffic, rider behavior, location-specific delays). Neither alone gives a good answer. The formula is too simple. Pure ML ignores obvious domain knowledge. The question becomes: how do you combine both?

My Approach

The first thing I did was calculate what a formula would give: distance divided by average rider speed. Then I asked the model to learn the residual — how much the real world deviates from this simple estimate, and in which direction. Rather than using the formula as the prediction or ignoring it entirely, I fed the analytical estimate into the model as a feature. The model's task became: predict how wrong the baseline estimate is.

This is a powerful pattern. The domain formula captures the structural component (longer distances take longer), while the ML model captures the contextual corrections (this rider is faster, this route has traffic, pickups in this area take longer). Together, they cover both the predictable physics and the unpredictable context. I also computed an "improvement ratio" — how much the current delivery context deviates from expectation — which gives the model a normalized signal about whether conditions are better or worse than average.

For rider profiling, I aggregated historical performance per rider: median speed, median duration, distance variability, and a composite quality score. Experienced riders with consistent speeds produce more predictable deliveries. For location intelligence, I applied K-Means clustering on all pickup and destination coordinates, creating geographic zone features that capture neighborhood-level patterns without requiring explicit area knowledge.

Feature selection used Weight of Evidence (WOE) analysis on a binarized target (above/below a duration threshold) to identify which features carry predictive signal versus noise. The final model combined H2O AutoML with XGBoost stacking — letting H2O explore the model space broadly while XGBoost provided a tuned gradient-boosted baseline.

Key Decisions

Domain Formula as Feature, Not as Prediction

The analytical estimate (distance/speed) becomes a feature for the ML model to correct rather than a competing approach. This turns domain knowledge into a structured prior — the model starts from physics and learns the contextual residual.

Rider Profiling from Historical Behavior

Each rider characterized by aggregated performance stats: median speed, duration patterns, distance variability. This encodes the reality that experienced, consistent riders are more predictable than new or variable ones — a fact invisible in individual delivery records.

K-Means Location Clustering

Geographic zones discovered by clustering pickup/destination coordinates capture neighborhood-level delivery patterns without requiring manual area definitions. This lets the model learn that certain zones have systematically longer or shorter deliveries.

WOE-Based Feature Selection

Information Value analysis on a binarized target identified which features genuinely discriminate between fast and slow deliveries. This prevented the model from training on noise features that correlate with duration in-sample but don't generalize.

Key Takeaway

The core lesson from this project is that domain knowledge and machine learning are not competing approaches — they're complementary layers. The physics formula sets the baseline. The ML model corrects the baseline using context. Together, they outperform either alone by a significant margin. Whenever a domain formula exists (however imperfect), use it as a feature rather than discarding it. Let the model learn what the formula gets wrong rather than rediscovering what it gets right.

Design insight: When a domain formula exists, don't compete with it — augment it. Feed the analytical estimate as a feature and let the ML model learn the residual. This combines structural domain knowledge with contextual pattern recognition for better predictions than either approach alone.

FAQ

What is the key takeaway from "Sendy Logistics ETA"?

When a domain formula exists, don't compete with it — augment it. Feed the analytical estimate as a feature and let the ML model learn the residual. This combines structural domain knowledge with contextual pattern recognition for better predictions than either approach alone.

Who wrote this and what is it about?

This was written by Mahmoud Trigui, Senior Data Scientist. Predicting motorbike delivery ETA in Nairobi using CatBoost, target encoding, and rider speed features. Ranked Top 26% (431/1143 competitors) on Zindi, November 2019.

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