Add urban_meal_delivery.forecasts.models sub-package
- `*Model`s use the `methods.*.predict()` functions to predict demand given an order time series generated by `timify.OrderHistory` - `models.base.ForecastingModelABC` unifies how all `*Model`s work and implements a caching strategy - implement three `*Model`s for tactical forecasting, based on the hets, varima, and rtarima models described in the first research paper - add overall documentation for `urban_meal_delivery.forecasts` package - move the fixtures in `tests.forecasts.timify.conftest` to `tests.forecasts.conftest` and adjust the horizon of the test horizon from two to three weeks
This commit is contained in:
parent
796fdc919c
commit
67cd58cf16
12 changed files with 747 additions and 71 deletions
|
|
@ -1,57 +0,0 @@
|
|||
"""Fixture for testing the `urban_meal_delivery.forecast.timify` module."""
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
from tests import config as test_config
|
||||
from urban_meal_delivery import config
|
||||
from urban_meal_delivery.forecasts import timify
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def good_pixel_id(pixel):
|
||||
"""A `pixel_id` that is on the `grid`."""
|
||||
return pixel.id # `== 1`
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def order_totals(good_pixel_id):
|
||||
"""A mock for `OrderHistory.totals`.
|
||||
|
||||
To be a bit more realistic, we sample two pixels on the `grid`.
|
||||
|
||||
Uses the LONG_TIME_STEP as the length of a time step.
|
||||
"""
|
||||
pixel_ids = [good_pixel_id, good_pixel_id + 1]
|
||||
|
||||
gen = (
|
||||
(pixel_id, start_at)
|
||||
for pixel_id in pixel_ids
|
||||
for start_at in pd.date_range(
|
||||
test_config.START, test_config.END, freq=f'{test_config.LONG_TIME_STEP}T',
|
||||
)
|
||||
if config.SERVICE_START <= start_at.hour < config.SERVICE_END
|
||||
)
|
||||
|
||||
# Re-index `data` filling in `0`s where there is no demand.
|
||||
index = pd.MultiIndex.from_tuples(gen)
|
||||
index.names = ['pixel_id', 'start_at']
|
||||
|
||||
df = pd.DataFrame(data={'n_orders': 1}, index=index)
|
||||
|
||||
# Sanity check: n_pixels * n_time_steps_per_day * n_weekdays * n_weeks.
|
||||
assert len(df) == 2 * 12 * (7 * 2 + 1)
|
||||
|
||||
return df
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def order_history(order_totals, grid):
|
||||
"""An `OrderHistory` object that does not need the database.
|
||||
|
||||
Uses the LONG_TIME_STEP as the length of a time step.
|
||||
"""
|
||||
oh = timify.OrderHistory(grid=grid, time_step=test_config.LONG_TIME_STEP)
|
||||
oh._data = order_totals
|
||||
|
||||
return oh
|
||||
|
|
@ -17,8 +17,8 @@ from urban_meal_delivery import config
|
|||
def good_predict_at():
|
||||
"""A `predict_at` within `START`-`END` and ...
|
||||
|
||||
... a long enough history so that either `train_horizon=1`
|
||||
or `train_horizon=2` works.
|
||||
... a long enough history so that either `SHORT_TRAIN_HORIZON`
|
||||
or `LONG_TRAIN_HORIZON` works.
|
||||
"""
|
||||
return datetime.datetime(
|
||||
test_config.END.year,
|
||||
|
|
@ -33,10 +33,10 @@ def good_predict_at():
|
|||
def bad_predict_at():
|
||||
"""A `predict_at` within `START`-`END` but ...
|
||||
|
||||
... not a long enough history so that both `train_horizon=1`
|
||||
and `train_horizon=2` do not work.
|
||||
... not a long enough history so that both `SHORT_TRAIN_HORIZON`
|
||||
and `LONG_TRAIN_HORIZON` do not work.
|
||||
"""
|
||||
predict_day = test_config.END - datetime.timedelta(weeks=1, days=1)
|
||||
predict_day = test_config.END - datetime.timedelta(weeks=2, days=1)
|
||||
return datetime.datetime(
|
||||
predict_day.year, predict_day.month, predict_day.day, test_config.NOON, 0,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue