An intelligent machine learning system that predicts food delivery times with high accuracy using delivery partner data, order characteristics, and location-based features.
Google Colab Notebook: View Code
- Problem Statement
- Key Features
- Project Architecture
- Dataset Description
- Methodology
- Model Performance
- Installation
- Usage
- Tech Stack
- Results & Insights
- Acknowledgments
- Contributors
Food delivery platforms operate in dynamic urban environments where accurate delivery time estimation is critical for customer satisfaction and operational efficiency. Traditional methods rely on static rules that fail to capture real-world variability.
Objective: Build an ML-based regression model to predict delivery time (in minutes) using historical delivery data and multiple influencing factors.
- Intelligent Prediction - ML-powered delivery time estimation using Gradient Boosting
- Comprehensive EDA - Visual insights into delivery patterns and correlations
- Feature Engineering - Haversine distance calculation for accurate location-based predictions
- Modern UI - Futuristic React interface with real-time predictions
- AI-Powered Analytics - Performance analysis using Google Gemini LLM
- Email Integration - Automated delivery of analysis results via Resend
- Production Ready - Saved model artifacts for seamless deployment
- Model Comparison - Evaluated multiple regression algorithms for optimal performance
Data Collection → EDA & Preprocessing → Feature Engineering → Model Training → Evaluation → Deployment
Phase 1: Data Understanding & Feature Engineering
- Data cleaning and sanity checks
- Exploratory Data Analysis (EDA)
- Distance calculation using Haversine formula
- Categorical encoding and feature transformation
Phase 2: Model Training & Evaluation
- Train-test split (80-20)
- Model comparison (Linear Regression, Random Forest, Gradient Boosting)
- Performance evaluation (MAE, RMSE)
- Feature importance analysis
Phase 3: Deployment & Integration
- Model serialization (.pkl)
- Interactive web application with React
- Streamlit dashboard for analytics
- Real-time prediction interface
- Email notification system
| Feature | Description | Type |
|---|---|---|
Delivery_person_Age |
Age of the delivery partner | Numerical |
Delivery_person_Ratings |
Rating of delivery partner (1-5) | Numerical |
Restaurant_latitude |
Restaurant location latitude | Numerical |
Restaurant_longitude |
Restaurant location longitude | Numerical |
Delivery_location_latitude |
Delivery location latitude | Numerical |
Delivery_location_longitude |
Delivery location longitude | Numerical |
Type_of_order |
Category of order | Categorical |
Type_of_vehicle |
Vehicle used for delivery | Categorical |
Time_taken(min) |
Target Variable - Delivery time | Numerical |
Dataset Quality:
- No missing values
- No duplicate entries
- Clean and ready for modeling
# Data validation
- Checked for nulls and duplicates
- Separated numerical and categorical features
- Validated data types and rangesDistance Calculation using Haversine Formula
from math import radians, sin, cos, sqrt, atan2
def haversine_distance(lat1, lon1, lat2, lon2):
"""
Calculate great-circle distance between two points
Returns distance in kilometers
"""
R = 6371 # Earth's radius in kilometers
lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])
dlat = lat2 - lat1
dlon = lon2 - lon1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * atan2(sqrt(a), sqrt(1-a))
return R * cCategorical Encoding
Type_of_order→ Numeric codesType_of_vehicle→ Numeric codes
Models Evaluated:
- Linear Regression (Baseline)
- Random Forest Regressor
- Gradient Boosting Regressor ✓ (Selected)
Final Feature Set:
X = [
'Delivery_person_Age',
'Delivery_person_Ratings',
'distance_km', # Engineered feature
'Type_of_order_encoded',
'Type_of_vehicle_encoded'
]| Model | MAE | RMSE | Status |
|---|---|---|---|
| Linear Regression | 6.64 | 8.46 | Baseline |
| Random Forest | 5.71 | 7.26 | Good |
| Gradient Boosting | 5.67 | 7.21 | ✓ Selected |
Performance Improvement:
- Gradient Boosting achieved 14.6% better MAE compared to Linear Regression baseline
- RMSE improved by 14.8%, demonstrating superior prediction accuracy
- Random Forest showed competitive performance with slight edge given to Gradient Boosting
- distance_km - Most influential predictor
- Delivery_person_Ratings - Strong predictor
- Delivery_person_Age - Moderate impact
- Type_of_vehicle_encoded - Minor impact
- Type_of_order_encoded - Minor impact
- Python 3.8+
- Node.js 16+
- npm or yarn
# Clone the repository
git clone https://github.com/yourusername/ai-delitime.git
cd ai-delitime
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start development server
npm start# Load and prepare data
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingRegressor
import pickle
# Load dataset
df = pd.read_csv('Dataset.csv')
# Feature engineering
df['distance_km'] = haversine_distance(
df['Restaurant_latitude'],
df['Restaurant_longitude'],
df['Delivery_location_latitude'],
df['Delivery_location_longitude']
)
# Train model
model = GradientBoostingRegressor()
model.fit(X_train, y_train)
# Save model
pickle.dump(model, open('delivery_time_model.pkl', 'wb'))# Load model
model = pickle.load(open('delivery_time_model.pkl', 'rb'))
# Prepare input
input_data = [[25, 4.5, 5.2, 1, 2]] # age, rating, distance, order, vehicle
# Predict
predicted_time = model.predict(input_data)
print(f"Estimated Delivery Time: {predicted_time[0]:.2f} minutes")- Open the web application
- Adjust delivery partner age using the slider
- Set delivery partner ratings (1.0 - 5.0)
- Enter distance in kilometers
- Select order type and vehicle type
- Enter email address
- Click "RUN ANALYSIS"
- Receive prediction results and AI-powered insights via email
- Python 3.8+ - Core programming language
- Scikit-learn - Model training and evaluation
- Pandas - Data manipulation
- NumPy - Numerical operations
- Matplotlib/Seaborn - Data visualization
- Streamlit - Analytics dashboard
- Google Gemini - LLM-powered performance analysis
- Html - Frontend
- CSS - Frontend
- Resend - Email delivery service
- Pickle - Model serialization
- Flask/FastAPI - Backend API
1. Delivery Time Distribution
- Normal distribution centered around 20-30 minutes
- Range: 10-60 minutes
- Peak frequency: ~25 minutes
2. Rating Impact
- Higher-rated partners deliver faster
- Strong negative correlation with delivery time
- Ratings > 4.0 show consistent performance
3. Vehicle Type Analysis
- Motorcycle - Most consistent delivery times
- Scooter - Slightly slower, similar variance
- Bicycle - Highest variance, weather-dependent
- Electric Scooter - Moderate performance
4. Distance Effect
- Strong positive correlation (r > 0.7)
- Linear relationship up to 15km
- Non-linear patterns beyond 15km
Special thanks to Intruv AI Hackathon for organizing this challenge and providing the opportunity to develop this solution.
Developed by First Round AI
- Piyush Kokane - @piyush-kokane
- Ruturaj Pawar - @Ruturaj-007
⭐ Star this repository if you found it helpful!
Made with dedication by the First Round AI team




