Estimating delivery times
Sample project · A small regression notebook using synthetic delivery data.
This example shows how a project and its notebook look on this site. It uses made-up data and does not represent a completed personal project.
The question
How much does delivery time change with distance? The notebook starts with a simple straight-line model, then checks its predictions on four held-out deliveries.
Approach
- Twelve synthetic samples.
- Eight training samples and four test samples.
- Linear regression using Python’s standard library.
- Mean absolute error for evaluation.
Result
The calculations and saved outputs are shown below. The small synthetic dataset makes this useful as a layout example, rather than a meaningful benchmark.
Next steps
Use real records, compare with a baseline, and add a Gradio demo once there is a model worth trying.
Notebook
Code and saved outputs, as recorded in the notebook.
Estimating delivery times
Sample project for the portfolio preview. The data below is synthetic. This is not a completed project by Oğuz.
The question is simple: can distance give us a rough estimate of delivery time? This notebook fits a small linear regression baseline using only Python’s standard library.
1. The data
Twelve made-up deliveries, with distance in kilometres and delivery time in minutes. The first eight are used for training; the last four are held out for evaluation.
| Distance (km) | Time (minutes) |
|---|---|
| 1 | 12 |
| 2 | 15 |
| 3 | 20 |
| 4 | 23 |
| 5 | 26 |
| 6 | 31 |
| 7 | 33 |
| 8 | 37 |
| 9 | 42 |
| 10 | 44 |
| 11 | 48 |
| 12 | 51 |
from statistics import linear_regression, mean
# Synthetic data, for demonstration only.
distances = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
minutes = [12, 15, 20, 23, 26, 31, 33, 37, 42, 44, 48, 51]
train_x, test_x = distances[:8], distances[8:]
train_y, test_y = minutes[:8], minutes[8:]
print(f"Training samples: {len(train_x)}")
print(f"Test samples: {len(test_x)}")
Training samples: 8 Test samples: 4
2. Fit a baseline
The model is a straight line: time = intercept + slope × distance. It is deliberately small so we can inspect each step.
slope, intercept = linear_regression(train_x, train_y)
def predict(distance_km):
return intercept + slope * distance_km
print(f"Intercept: {intercept:.2f} minutes")
print(f"Slope: {slope:.2f} minutes per kilometre")
Intercept: 8.50 minutes Slope: 3.58 minutes per kilometre
3. Check the held-out deliveries
Mean absolute error (MAE) measures the average difference between predicted and recorded times, in minutes. With only four synthetic test samples, this is a demonstration of evaluation, not evidence that the model works in practice.
predictions = [predict(distance) for distance in test_x]
mae = mean(abs(actual - predicted)
for actual, predicted in zip(test_y, predictions))
print("Distance Actual Predicted")
for distance, actual, predicted in zip(test_x, test_y, predictions):
print(f"{distance:>5} km {actual:>4} m {predicted:>7.1f} m")
print(f"\nMean absolute error: {mae:.2f} minutes")
Distance Actual Predicted
9 km 42 m 40.8 m
10 km 44 m 44.3 m
11 km 48 m 47.9 m
12 km 51 m 51.5 m
Mean absolute error: 0.54 minutes
4. Try a prediction
A delivery of 6.5 km sits within the training range. Distances far beyond that range would be less trustworthy.
distance = 6.5
estimate = predict(distance)
print(f"Estimated time for {distance} km: {estimate:.1f} minutes")
Estimated time for 6.5 km: 31.8 minutes
What this leaves out
Distance alone ignores traffic, preparation time, weather and the delivery route. A real experiment would need actual delivery records, a larger test set, and a comparison with a simple average-time baseline.
A next step could be a Gradio form with a distance input. No live demo is connected to this sample.