Upload folder using huggingface_hub
Browse files- .gitattributes +3 -0
- README.md +149 -0
- final_hgb_eta_pipeline.joblib +3 -0
- reports/feature_importance.csv +22 -0
- reports/figures/interp_error_by_hour_market.png +0 -0
- reports/figures/interp_partial_dependence.png +3 -0
- reports/figures/interp_permutation_importance.png +3 -0
- reports/figures/test_actual_vs_predicted.png +3 -0
- reports/figures/test_error_by_band.png +0 -0
- reports/figures/test_residuals_distribution.png +0 -0
- reports/figures/test_vs_val_comparison.png +0 -0
- reports/final_test_evaluation_report.md +98 -0
- reports/final_test_metrics.json +119 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
reports/figures/interp_partial_dependence.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
reports/figures/interp_permutation_importance.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
reports/figures/test_actual_vs_predicted.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- pt
|
| 4 |
+
license: mit
|
| 5 |
+
library_name: scikit-learn
|
| 6 |
+
tags:
|
| 7 |
+
- tabular-regression
|
| 8 |
+
- delivery-eta
|
| 9 |
+
- histgradientboosting
|
| 10 |
+
- scikit-learn
|
| 11 |
+
metrics:
|
| 12 |
+
- mae
|
| 13 |
+
- rmse
|
| 14 |
+
- r2
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# DoorDash Delivery ETA Prediction (`HistGradientBoostingRegressor`)
|
| 18 |
+
|
| 19 |
+
> **AVISO IMPORTANTE:** Este modelo é **experimental** e **não está pronto para uso em produção real**. Trata-se de um modelo conservador de referência treinado exclusivamente com atributos confirmados no momento da criação do pedido, apresentando `R² = +0,0288` no conjunto de teste.
|
| 20 |
+
|
| 21 |
+
## Descrição e Objetivo
|
| 22 |
+
|
| 23 |
+
Pipeline de Machine Learning (`ColumnTransformer` + `HistGradientBoostingRegressor`) desenvolvido para prever a duração total de entrega de pedidos de delivery (`delivery_duration_minutes`) a partir de informações disponíveis no momento do checkout.
|
| 24 |
+
|
| 25 |
+
- **Repositório de código e notebooks (GitHub):** https://github.com/CarvalhoAdryan/DeliveryETA
|
| 26 |
+
- **Artefato do modelo:** `final_hgb_eta_pipeline.joblib`
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## Dataset e Origem
|
| 31 |
+
|
| 32 |
+
- **Origem:** `historical_data.csv` disponibilizado pela **StrataScratch** no exercício *DoorDash Delivery Duration Prediction* (`197.428` linhas × `16` colunas originais; `197.421` válidas após remoção de `7` registros sem `actual_delivery_time`).
|
| 33 |
+
- **Redistribuição:** O dataset bruto **não é redistribuído** neste repositório.
|
| 34 |
+
- **Variável-alvo:** `delivery_duration_minutes = (actual_delivery_time - created_at).dt.total_seconds() / 60.0`.
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## Features Utilizadas (`21` variáveis confirmadas)
|
| 39 |
+
|
| 40 |
+
O modelo utiliza exclusivamente atributos com disponibilidade confirmada no instante de criação do pedido (`store_id` foi excluído do One-Hot Encoding por alta cardinalidade — `6.743` níveis — e variáveis operacionais/rota de disponibilidade incerta foram mantidas fora do modelo conservador):
|
| 41 |
+
|
| 42 |
+
- **Metadados (One-Hot Encoding):** `market_id`, `store_primary_category`, `order_protocol`, `created_time_block`
|
| 43 |
+
- **Carrinho e valores:** `total_items`, `subtotal`, `num_distinct_items`, `min_item_price`, `max_item_price`, `average_item_price`, `item_price_range`, `invalid_item_price_range`, `distinct_item_ratio`, `is_single_item`, `is_large_order`
|
| 44 |
+
- **Temporais (horário registrado, aparente UTC):** `created_hour`, `created_dayofweek`, `created_month`, `created_is_weekend`
|
| 45 |
+
- **Histórico causal e protocolo:** `estimated_order_place_duration`, `historical_store_order_count`
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## Algoritmo, Hiperparâmetros e Validação Temporal
|
| 50 |
+
|
| 51 |
+
- **Algoritmo:** `sklearn.ensemble.HistGradientBoostingRegressor`
|
| 52 |
+
- **Hiperparâmetros congelados (Etapa 06.2):**
|
| 53 |
+
- `loss="absolute_error"` (escolhida para robustez a outliers `> 24h` sem excluí-los do treino)
|
| 54 |
+
- `learning_rate=0.08`
|
| 55 |
+
- `max_iter=20` (definido via validação interna temporal 90/10 dentro do treino)
|
| 56 |
+
- `max_leaf_nodes=63`
|
| 57 |
+
- `min_samples_leaf=30`
|
| 58 |
+
- `l2_regularization=0.0`
|
| 59 |
+
- `early_stopping=False`
|
| 60 |
+
- `random_state=42`
|
| 61 |
+
- **Divisão Temporal com Embargo (Etapa 05, cortes às `10:00:00` UTC):**
|
| 62 |
+
- **Treino:** `138.572` registros (`created_at < 2015-02-10 10:00:00`, entregas concluídas antes do corte)
|
| 63 |
+
- **Validação:** `28.808` registros (`2015-02-10 10:00:00` a `2015-02-14 10:00:00`)
|
| 64 |
+
- **Teste (isolado até a Etapa 07):** `30.041` registros (`created_at >= 2015-02-14 10:00:00`)
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## Resultados (Validação e Teste Final)
|
| 69 |
+
|
| 70 |
+
| Conjunto | Modelo | MAE (min) | RMSE (min) | MedAE (min) | P90_AE (min) | R² | Mean Bias |
|
| 71 |
+
| :--- | :--- | ---: | ---: | ---: | ---: | ---: | ---: |
|
| 72 |
+
| **Validação** (`n=28.808`) | Baseline (Median) | 12,8201 | 18,6790 | 9,9000 | 25,6667 | -0,0341 | -3,3927 |
|
| 73 |
+
| **Validação** (`n=28.808`) | **HGB Congelado** | **12,1142** | **17,9219** | **9,2317** | **24,7196** | **+0,0480** | -2,8943 |
|
| 74 |
+
| **Teste** (`n=30.041`) | Baseline (Median) | 14,1955 | 38,1036 | 10,4667 | 29,0833 | -0,0195 | -5,2643 |
|
| 75 |
+
| **Teste** (`n=30.041`) | **HGB Congelado** | **12,7797** | **37,1903** | **9,2282** | **25,9125** | **+0,0288** | -4,6494 |
|
| 76 |
+
|
| 77 |
+
- **Ganho sobre o baseline no teste:** `-9,97%` em MAE (`-1,4158 min`), `-11,83%` em MedAE (`-1,2385 min`), `-10,90%` em P90_AE (`-3,1708 min`) e `-2,40%` em RMSE (`-0,9133 min`).
|
| 78 |
+
- **Tempo de treino:** `4,12 s` | **Inferência no teste (`30.041`):** `0,124 s`.
|
| 79 |
+
|
| 80 |
+

|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
## Interpretabilidade
|
| 85 |
+
|
| 86 |
+
Por *Permutation Importance* na validação (`neg_mean_absolute_error`, `n=28.808`), as variáveis mais relevantes para reduzir o MAE foram:
|
| 87 |
+
1. `created_hour` (`+0,77159 min`)
|
| 88 |
+
2. `subtotal` (`+0,41535 min`)
|
| 89 |
+
3. `market_id` (`+0,13144 min`)
|
| 90 |
+
4. `created_dayofweek` (`+0,09240 min`)
|
| 91 |
+
5. `estimated_order_place_duration` (`+0,08987 min`)
|
| 92 |
+
|
| 93 |
+
*(Importância preditiva não implica causalidade.)*
|
| 94 |
+
|
| 95 |
+

|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## Limitações e Possíveis Aplicações
|
| 100 |
+
|
| 101 |
+
- **Limitações:**
|
| 102 |
+
- Baixo poder explicativo (`R² = +0,0288` no teste) por usar apenas atributos estáticos de checkout.
|
| 103 |
+
- Superestimação em entregas rápidas (`<= 30 min`: Mean Bias `+15,62 min` no teste) e forte subestimação em atrasos (`> 120 min`: Mean Bias `-135,20 min` no teste).
|
| 104 |
+
- Janela curta (~1 mês em 2015), timestamps em provável UTC sem fuso local por mercado e ausência de sinais em tempo real confirmados (congestionamento e distância de rota).
|
| 105 |
+
- **Aplicações adequadas:** Estudo de portfólio, referência de baseline conservador com validação temporal rigorosa e ponto de partida para uma v2 com variáveis operacionais validadas e *target encoding* causal por loja.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## Como Carregar e Prever
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
import joblib
|
| 113 |
+
import pandas as pd
|
| 114 |
+
|
| 115 |
+
pipeline = joblib.load("final_hgb_eta_pipeline.joblib")
|
| 116 |
+
|
| 117 |
+
sample = pd.DataFrame([{
|
| 118 |
+
"market_id": "1",
|
| 119 |
+
"store_primary_category": "american",
|
| 120 |
+
"order_protocol": "1",
|
| 121 |
+
"total_items": 3,
|
| 122 |
+
"subtotal": 2500,
|
| 123 |
+
"num_distinct_items": 2,
|
| 124 |
+
"min_item_price": 600.0,
|
| 125 |
+
"max_item_price": 1200,
|
| 126 |
+
"estimated_order_place_duration": 446,
|
| 127 |
+
"created_hour": 2,
|
| 128 |
+
"created_dayofweek": 5,
|
| 129 |
+
"created_month": 2,
|
| 130 |
+
"created_is_weekend": 1,
|
| 131 |
+
"created_time_block": "00-05h_reg",
|
| 132 |
+
"average_item_price": 833.33,
|
| 133 |
+
"item_price_range": 600.0,
|
| 134 |
+
"invalid_item_price_range": 0,
|
| 135 |
+
"distinct_item_ratio": 0.6667,
|
| 136 |
+
"is_single_item": 0,
|
| 137 |
+
"is_large_order": 0,
|
| 138 |
+
"historical_store_order_count": 25,
|
| 139 |
+
}])
|
| 140 |
+
|
| 141 |
+
eta_minutes = pipeline.predict(sample)[0]
|
| 142 |
+
print(f"ETA previsto: {eta_minutes:.2f} minutos")
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## Uso de Ferramentas de IA
|
| 148 |
+
|
| 149 |
+
Ferramentas de inteligência artificial foram utilizadas como apoio ao longo do desenvolvimento deste projeto nas atividades de pesquisa técnica, auxílio na escrita/depuração de código, discussão de resultados exploratórios e organização da documentação. Todas as decisões metodológicas, verificações de integridade e resultados foram validados diretamente pela execução real dos experimentos.
|
final_hgb_eta_pipeline.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:af4ebcd8f5874ff93f9bcd8232a2cd02ce33299d8453e2ec47ac31e878281a2d
|
| 3 |
+
size 175186
|
reports/feature_importance.csv
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
feature,importance_mean_mae,importance_std,rank
|
| 2 |
+
created_hour,0.77159,0.01724,1
|
| 3 |
+
subtotal,0.41535,0.00803,2
|
| 4 |
+
market_id,0.13144,0.00992,3
|
| 5 |
+
created_dayofweek,0.0924,0.01085,4
|
| 6 |
+
estimated_order_place_duration,0.08987,0.00651,5
|
| 7 |
+
order_protocol,0.04374,0.00158,6
|
| 8 |
+
store_primary_category,0.04217,0.00158,7
|
| 9 |
+
historical_store_order_count,0.0165,0.00258,8
|
| 10 |
+
max_item_price,0.00882,0.00047,9
|
| 11 |
+
num_distinct_items,0.00872,0.0008,10
|
| 12 |
+
total_items,0.00358,0.00015,11
|
| 13 |
+
average_item_price,0.00244,0.00024,12
|
| 14 |
+
item_price_range,0.00165,0.00039,13
|
| 15 |
+
created_time_block,0.00153,0.00137,14
|
| 16 |
+
min_item_price,0.0009,8e-05,15
|
| 17 |
+
distinct_item_ratio,8e-05,8e-05,16
|
| 18 |
+
created_month,0.0,0.0,17
|
| 19 |
+
created_is_weekend,0.0,0.0,18
|
| 20 |
+
invalid_item_price_range,0.0,0.0,19
|
| 21 |
+
is_single_item,0.0,0.0,20
|
| 22 |
+
is_large_order,0.0,0.0,21
|
reports/figures/interp_error_by_hour_market.png
ADDED
|
reports/figures/interp_partial_dependence.png
ADDED
|
Git LFS Details
|
reports/figures/interp_permutation_importance.png
ADDED
|
Git LFS Details
|
reports/figures/test_actual_vs_predicted.png
ADDED
|
Git LFS Details
|
reports/figures/test_error_by_band.png
ADDED
|
reports/figures/test_residuals_distribution.png
ADDED
|
reports/figures/test_vs_val_comparison.png
ADDED
|
reports/final_test_evaluation_report.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# DoorDash Delivery ETA — Relatório de Avaliação Final no Conjunto de Teste (Etapa 07)
|
| 2 |
+
|
| 3 |
+
**Data de execução:** `2026-11-17T16:25:07-03:00`
|
| 4 |
+
**Notebook:** [07_final_test_evaluation.ipynb](../notebooks/07_final_test_evaluation.ipynb)
|
| 5 |
+
**Métricas (JSON):** [final_test_metrics.json](final_test_metrics.json)
|
| 6 |
+
**Pipeline salvo:** `models/final_hgb_eta_pipeline.joblib`
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 1. Configuração Congelada Avaliada
|
| 11 |
+
|
| 12 |
+
- **Modelo:** `HistGradientBoostingRegressor`
|
| 13 |
+
- **Parâmetros:** `loss="absolute_error"`, `learning_rate=0.08`, `max_iter=20`, `max_leaf_nodes=63`, `min_samples_leaf=30`, `l2_regularization=0.0`, `early_stopping=False`, `random_state=42`
|
| 14 |
+
- **Features:** `CONFIRMED_MODEL_FEATURES` (`21` variáveis confirmadas; `store_id` e variáveis experimentais excluídos)
|
| 15 |
+
- **Target:** `delivery_duration_minutes`
|
| 16 |
+
- **Divisão temporal (Etapa 05):**
|
| 17 |
+
- Treino: `138.572` registros (`created_at < 2015-02-10 10:00:00`, `actual_delivery_time` máx: `2015-02-10 06:55:06`)
|
| 18 |
+
- Validação: `28.808` registros (`2015-02-10 14:37:17` – `2015-02-14 07:00:55`)
|
| 19 |
+
- Teste: `30.041` registros (`2015-02-14 14:37:07` – `2015-02-18 06:00:44`, todos mantidos)
|
| 20 |
+
- **Versões:** Python `3.12.3` | `pandas 2.3.1` | `numpy 2.3.2` | `scikit-learn 1.8.0` | `scipy 1.17.1` | `joblib 1.5.3` | `matplotlib 3.10.6` | `seaborn 0.13.2`
|
| 21 |
+
- **Tempo de treino:** `4,21 s` | **Inferência no teste (`30.041`):** `0,122 s`
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 2. Resultados no Conjunto de Teste (`n = 30.041`) e Comparação com Baseline
|
| 26 |
+
|
| 27 |
+
| Métrica | Baseline (Median) — Teste | HGB Congelado — Teste | Diferença Absoluta | Diferença % |
|
| 28 |
+
| :--- | ---: | ---: | ---: | ---: |
|
| 29 |
+
| **MAE (min)** | 14,1955 | **12,7797** | **-1,4158** | **-9,97%** |
|
| 30 |
+
| **RMSE (min)** | 38,1036 | **37,1903** | **-0,9133** | **-2,40%** |
|
| 31 |
+
| **MedAE (min)** | 10,4667 | **9,2282** | **-1,2385** | **-11,83%** |
|
| 32 |
+
| **P90_AE (min)** | 29,0833 | **25,9125** | **-3,1708** | **-10,90%** |
|
| 33 |
+
| **R²** | -0,0195 | **+0,0288** | +0,0483 | — |
|
| 34 |
+
| **Mean Bias (min)** | -5,2643 | -4,6494 | — | — |
|
| 35 |
+
| **Median Bias (min)** | -1,4500 | -1,1213 | — | — |
|
| 36 |
+
|
| 37 |
+
- O modelo congelado superou o baseline em **todas** as métricas de erro no teste, reduzindo o MAE em `9,97%` (`1,42 min`), a MedAE em `11,83%` e o P90_AE em `10,90%`.
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
+
## 3. Comparação Validação vs Teste (Generalização Temporal)
|
| 42 |
+
|
| 43 |
+
| Conjunto | Modelo | MAE | RMSE | MedAE | P90_AE | R² | Mean Bias |
|
| 44 |
+
| :--- | :--- | ---: | ---: | ---: | ---: | ---: | ---: |
|
| 45 |
+
| **Validação** (`n=28.808`) | Baseline | 12,8201 | 18,6790 | 9,9000 | 25,6667 | -0,0341 | -3,3927 |
|
| 46 |
+
| **Validação** (`n=28.808`) | HGB Congelado | 12,1142 | 17,9219 | 9,2317 | 24,7196 | +0,0480 | -2,8943 |
|
| 47 |
+
| **Teste** (`n=30.041`) | Baseline | 14,1955 | 38,1036 | 10,4667 | 29,0833 | -0,0195 | -5,2643 |
|
| 48 |
+
| **Teste** (`n=30.041`) | HGB Congelado | 12,7797 | 37,1903 | 9,2282 | 25,9125 | +0,0288 | -4,6494 |
|
| 49 |
+
|
| 50 |
+
- **Análise de generalização:** A `MedAE` do modelo congelado manteve-se praticamente idêntica entre validação (`9,23 min`) e teste (`9,23 min`), e o ganho relativo sobre o baseline ampliou-se (`-1,42 min` no teste vs `-0,71 min` na validação).
|
| 51 |
+
- **Por que MAE e RMSE absolutos subiram no teste?** O próprio baseline constante piorou fortemente no teste (`MAE 12,82 → 14,20`; `RMSE 18,68 → 38,10`), refletindo uma mudança na distribuição do alvo no período de teste (`2015-02-14` a `2015-02-18`), que inclui maior proporção de entregas `> 120 min` (`191` no teste vs `116` na validação) e um outlier extremo `> 24h` (`5.541,37 min`).
|
| 52 |
+
|
| 53 |
+

|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## 4. Diagnóstico de Erros no Conjunto de Teste (`n = 30.041`)
|
| 58 |
+
|
| 59 |
+
- **Previsões negativas (`< 0`):** `0`
|
| 60 |
+
- **Erros absolutos por limite:**
|
| 61 |
+
- `> 30 min`: `2.232` (`7,43%`)
|
| 62 |
+
- `> 60 min`: `351` (`1,17%`)
|
| 63 |
+
- `> 90 min`: `76` (`0,25%`)
|
| 64 |
+
- `> 120 min`: `25` (`0,08%`)
|
| 65 |
+
|
| 66 |
+
### 4.1 Erros por Faixa de Duração Real
|
| 67 |
+
|
| 68 |
+
| Faixa de Duração Real | `n` | MAE (min) | MedAE (min) | P90_AE (min) | Mean Bias (min) |
|
| 69 |
+
| :--- | ---: | ---: | ---: | ---: | ---: |
|
| 70 |
+
| `<= 30 min` | 3.453 | 15,62 | 15,05 | 21,86 | +15,62 |
|
| 71 |
+
| `30-45 min` | 11.214 | **6,10** | **5,35** | 12,25 | +5,21 |
|
| 72 |
+
| `45-60 min` | 8.574 | 7,35 | 6,64 | 14,49 | -6,23 |
|
| 73 |
+
| `60-90 min` | 5.794 | 22,65 | 21,85 | 35,48 | -22,65 |
|
| 74 |
+
| `90-120 min` | 815 | 50,96 | 50,28 | 64,97 | -50,96 |
|
| 75 |
+
| **`> 120 min`** | **191** | **135,20** | **87,00** | **135,46** | **-135,20** |
|
| 76 |
+
|
| 77 |
+
### 4.2 Registros Extremos no Teste (Top 5 Maiores Erros Absolutos)
|
| 78 |
+
|
| 79 |
+
| Índice | `created_at` | `actual_delivery_time` | Real (min) | Previsto (min) | Erro Abs. (min) |
|
| 80 |
+
| ---: | :--- | :--- | ---: | ---: | ---: |
|
| 81 |
+
| `27187` | `2015-02-16 02:24:09` | `2015-02-19 22:45:31` | 5.541,37 (~92,4h) | 58,84 | 5.482,53 |
|
| 82 |
+
| `190853` | `2015-02-16 02:31:05` | `2015-02-16 17:38:32` | 907,45 (~15,1h) | 59,49 | 847,96 |
|
| 83 |
+
| `76741` | `2015-02-15 04:17:35` | `2015-02-15 16:59:00` | 761,42 (~12,7h) | 46,37 | 715,04 |
|
| 84 |
+
| `31183` | `2015-02-14 22:23:13` | `2015-02-15 07:19:12` | 535,98 (~8,9h) | 38,24 | 497,74 |
|
| 85 |
+
| `29713` | `2015-02-14 21:08:06` | `2015-02-15 04:14:44` | 426,63 (~7,1h) | 36,74 | 389,90 |
|
| 86 |
+
|
| 87 |
+
*(Os `20` maiores erros absolutos no teste correspondem a entregas reais entre `177,10` e `5.541,37 min`, para as quais o modelo previu entre `36,74` e `59,49 min`.)*
|
| 88 |
+
|
| 89 |
+

|
| 90 |
+

|
| 91 |
+

|
| 92 |
+
|
| 93 |
+
---
|
| 94 |
+
|
| 95 |
+
## 5. Limitações e Avaliação Honesta de Prontidão
|
| 96 |
+
|
| 97 |
+
- **O modelo NÃO está pronto para produção real.** Embora supere consistentemente o baseline com rigor metodológico e zero vazamento, o `R² = +0,0288` no teste indica que metadados estáticos do pedido e atributos temporais explicam apenas uma fração pequena da variância do tempo de entrega.
|
| 98 |
+
- **Principais lacunas:** (1) ausência de sinais em tempo real confirmados de congestionamento operacional e distância/tempo de rota (`driving_duration`), que nas ablações de validação elevaram o R² para `+0,1538`; (2) ausência do efeito específico por restaurante (`store_id`) via *target encoding* temporal causal; e (3) incapacidade de antecipar atrasos extremos (`> 90 min` / `> 24h`) a partir apenas das 21 variáveis confirmadas.
|
reports/final_test_metrics.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"executed_at": "2026-11-17T16:25:20",
|
| 3 |
+
"library_versions": {
|
| 4 |
+
"python": "3.12.3",
|
| 5 |
+
"pandas": "2.3.1",
|
| 6 |
+
"numpy": "2.3.2",
|
| 7 |
+
"scikit_learn": "1.8.0",
|
| 8 |
+
"scipy": "1.17.1",
|
| 9 |
+
"joblib": "1.5.3",
|
| 10 |
+
"matplotlib": "3.10.6",
|
| 11 |
+
"seaborn": "0.13.2"
|
| 12 |
+
},
|
| 13 |
+
"split_sizes": {
|
| 14 |
+
"train": 138572,
|
| 15 |
+
"val": 28808,
|
| 16 |
+
"test": 30041
|
| 17 |
+
},
|
| 18 |
+
"frozen_model": "HistGradientBoostingRegressor",
|
| 19 |
+
"frozen_params": {
|
| 20 |
+
"loss": "absolute_error",
|
| 21 |
+
"learning_rate": 0.08,
|
| 22 |
+
"max_iter": 20,
|
| 23 |
+
"max_leaf_nodes": 63,
|
| 24 |
+
"min_samples_leaf": 30,
|
| 25 |
+
"l2_regularization": 0.0,
|
| 26 |
+
"early_stopping": false,
|
| 27 |
+
"random_state": 42
|
| 28 |
+
},
|
| 29 |
+
"features": [
|
| 30 |
+
"market_id",
|
| 31 |
+
"store_primary_category",
|
| 32 |
+
"order_protocol",
|
| 33 |
+
"total_items",
|
| 34 |
+
"subtotal",
|
| 35 |
+
"num_distinct_items",
|
| 36 |
+
"min_item_price",
|
| 37 |
+
"max_item_price",
|
| 38 |
+
"estimated_order_place_duration",
|
| 39 |
+
"created_hour",
|
| 40 |
+
"created_dayofweek",
|
| 41 |
+
"created_month",
|
| 42 |
+
"created_is_weekend",
|
| 43 |
+
"created_time_block",
|
| 44 |
+
"average_item_price",
|
| 45 |
+
"item_price_range",
|
| 46 |
+
"invalid_item_price_range",
|
| 47 |
+
"distinct_item_ratio",
|
| 48 |
+
"is_single_item",
|
| 49 |
+
"is_large_order",
|
| 50 |
+
"historical_store_order_count"
|
| 51 |
+
],
|
| 52 |
+
"train_time_s": 4.12,
|
| 53 |
+
"test_infer_time_s": 0.124,
|
| 54 |
+
"validation_metrics": {
|
| 55 |
+
"baseline": {
|
| 56 |
+
"MAE": 12.8201,
|
| 57 |
+
"RMSE": 18.679,
|
| 58 |
+
"MedAE": 9.9,
|
| 59 |
+
"P90_AE": 25.6667,
|
| 60 |
+
"R2": -0.0341,
|
| 61 |
+
"Mean_Bias": -3.3927,
|
| 62 |
+
"Median_Bias": -0.6333
|
| 63 |
+
},
|
| 64 |
+
"frozen_hgb": {
|
| 65 |
+
"MAE": 12.1142,
|
| 66 |
+
"RMSE": 17.9219,
|
| 67 |
+
"MedAE": 9.2317,
|
| 68 |
+
"P90_AE": 24.7196,
|
| 69 |
+
"R2": 0.048,
|
| 70 |
+
"Mean_Bias": -2.8943,
|
| 71 |
+
"Median_Bias": -0.4005
|
| 72 |
+
}
|
| 73 |
+
},
|
| 74 |
+
"test_metrics": {
|
| 75 |
+
"baseline": {
|
| 76 |
+
"MAE": 14.1955,
|
| 77 |
+
"RMSE": 38.1036,
|
| 78 |
+
"MedAE": 10.4667,
|
| 79 |
+
"P90_AE": 29.0833,
|
| 80 |
+
"R2": -0.0195,
|
| 81 |
+
"Mean_Bias": -5.2643,
|
| 82 |
+
"Median_Bias": -1.45
|
| 83 |
+
},
|
| 84 |
+
"frozen_hgb": {
|
| 85 |
+
"MAE": 12.7797,
|
| 86 |
+
"RMSE": 37.1903,
|
| 87 |
+
"MedAE": 9.2282,
|
| 88 |
+
"P90_AE": 25.9125,
|
| 89 |
+
"R2": 0.0288,
|
| 90 |
+
"Mean_Bias": -4.6494,
|
| 91 |
+
"Median_Bias": -1.1213
|
| 92 |
+
}
|
| 93 |
+
},
|
| 94 |
+
"test_diff_vs_baseline": {
|
| 95 |
+
"MAE": {
|
| 96 |
+
"abs_diff": -1.4158,
|
| 97 |
+
"pct_diff": -9.97
|
| 98 |
+
},
|
| 99 |
+
"RMSE": {
|
| 100 |
+
"abs_diff": -0.9133,
|
| 101 |
+
"pct_diff": -2.4
|
| 102 |
+
},
|
| 103 |
+
"MedAE": {
|
| 104 |
+
"abs_diff": -1.2385,
|
| 105 |
+
"pct_diff": -11.83
|
| 106 |
+
},
|
| 107 |
+
"P90_AE": {
|
| 108 |
+
"abs_diff": -3.1708,
|
| 109 |
+
"pct_diff": -10.9
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
"test_error_counts": {
|
| 113 |
+
"negative_predictions": 0,
|
| 114 |
+
"abs_err_gt_30m": 2232,
|
| 115 |
+
"abs_err_gt_60m": 351,
|
| 116 |
+
"abs_err_gt_90m": 76,
|
| 117 |
+
"abs_err_gt_120m": 25
|
| 118 |
+
}
|
| 119 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
scikit-learn==1.8.0
|
| 2 |
+
pandas>=2.3.1
|
| 3 |
+
numpy>=2.3.2
|
| 4 |
+
scipy>=1.17.1
|
| 5 |
+
joblib>=1.5.3
|