5. Features and training

Features, pipeline and tuning

Each model gets the same six inputs and the same preprocessing. Only the final regressor changes. Settings are chosen on the validation orders, never on the test orders.

The six inputs

Every input is something the app knows the moment the customer presses predict. Importance is how much the validation error grows, in minutes, when that input's values are shuffled between orders.

InputTypeWhere the app gets itImportance (XGBoost)
Order hourNumberOrder time in the restaurant's time zone+1.07 min
Road distance (km)NumberOSRM road route from the restaurant to the pin+0.55 min
FestivalCategoryFestival checkbox on the predict page+0.53 min
City typeCategoryStored on the restaurant+0.32 min
Order typeCategoryOrder type control on the predict page+0.00 min
Day of weekNumberOrder date in the restaurant's time zone+0.00 min

Why road distance instead of a straight line

The dataset only has coordinates. The first version of the model used the straight-line distance between them. But a rider follows roads, and the app measures the actual route on the map, so a model trained on straight lines would receive a different kind of number in the app than it learned from. Training now uses the same OSRM road route the app shows, added to every order by ml.scripts.enrich_routes.

In this dataset both distances relate to delivery time about equally (correlation 0.32 for the straight line and 0.31 for the road), so the switch isn't about squeezing out accuracy. It makes training and the app measure the same thing.

The preprocessing pipeline

ml/pipeline.py builds one scikit-learn pipeline. It's fitted on training orders only and saved whole, so the API transforms each order exactly as training did.

Hyperparameter tuning

Each model is fitted once per combination in its grid and scored on the validation orders. The best combination is then refitted on training and validation orders together before the final test. For reference, the median baseline has a validation error of 7.77 min.

Decision Tree

Depth 3, 5 or 8 × at least 20 or 80 orders per leaf: 6 combinations.

depth 8, min leaf 20Best
6.25 min
depth 5, min leaf 20
6.33 min
depth 8, min leaf 80
6.33 min
depth 5, min leaf 80
6.38 min
depth 3, min leaf 20
6.56 min
depth 3, min leaf 80
6.59 min

Best: depth 8, min leaf 20, validation MAE 6.25 min. The worst setting is 0.34 min worse.

Show the numbers
SettingsMAERMSER²
depth 8, min leaf 206.2527.8360.335
depth 5, min leaf 206.3267.9430.317
depth 8, min leaf 806.3287.9410.317
depth 5, min leaf 806.3838.0210.303
depth 3, min leaf 206.5578.2510.263
depth 3, min leaf 806.5938.2820.257

XGBoostSelected

Depth 3 or 5 × learning rate 0.03 or 0.1 × 150 or 300 trees: 8 combinations.

learning rate 0.03, depth 5, trees 300Best
6.16 min
learning rate 0.1, depth 3, trees 150
6.16 min
learning rate 0.03, depth 3, trees 300
6.17 min
learning rate 0.03, depth 5, trees 150
6.17 min
learning rate 0.1, depth 3, trees 300
6.17 min
learning rate 0.1, depth 5, trees 150
6.17 min
learning rate 0.1, depth 5, trees 300
6.21 min
learning rate 0.03, depth 3, trees 150
6.23 min

Best: learning rate 0.03, depth 5, trees 300, validation MAE 6.16 min. The worst setting is 0.07 min worse.

Show the numbers
SettingsMAERMSER²
learning rate 0.03, depth 5, trees 3006.1607.7110.356
learning rate 0.1, depth 3, trees 1506.1627.7160.355
learning rate 0.03, depth 3, trees 3006.1677.7180.355
learning rate 0.03, depth 5, trees 1506.1697.7160.355
learning rate 0.1, depth 3, trees 3006.1727.7210.354
learning rate 0.1, depth 5, trees 1506.1757.7250.354
learning rate 0.1, depth 5, trees 3006.2137.7770.345
learning rate 0.03, depth 3, trees 1506.2317.7820.344

Feature importance

How much validation MAE grows when each input is shuffled, averaged over five shuffles. Larger means the model relies on it more.

  • Decision Tree
  • XGBoost
Order hour
1.13 min
1.07 min
Road distance (km)
0.60 min
0.55 min
Festival
0.43 min
0.53 min
City type
0.27 min
0.32 min
Order type
0.00 min
0.00 min
Day of week
0.00 min
0.00 min

Order hour matters most, then road distance and festival. Order type and day of the week barely matter, which matches the exploratory analysis.

Show the numbers
InputDecision TreeXGBoost
Order hour1.134 min1.066 min
Road distance (km)0.604 min0.551 min
Festival0.433 min0.526 min
City type0.267 min0.322 min
Order type-0.005 min0.002 min
Day of week-0.002 min0.002 min