Move decomposition
module into methods
sub-package
- move the module - unify the corresponding tests in `tests.forecasts.methods` sub-package - make all `predict()` and the `stl()` function round results - streamline documentation
This commit is contained in:
parent
a5b590b24c
commit
08b748c867
9 changed files with 21 additions and 14 deletions
|
@ -147,7 +147,7 @@ per-file-ignores =
|
|||
src/urban_meal_delivery/db/restaurants.py:
|
||||
# The module is not too complex.
|
||||
WPS232,
|
||||
src/urban_meal_delivery/forecasts/decomposition.py:
|
||||
src/urban_meal_delivery/forecasts/methods/decomposition.py:
|
||||
# The module is not too complex.
|
||||
WPS232,
|
||||
src/urban_meal_delivery/forecasts/timify.py:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Demand forecasting utilities."""
|
||||
|
||||
from urban_meal_delivery.forecasts import decomposition
|
||||
from urban_meal_delivery.forecasts import methods
|
||||
from urban_meal_delivery.forecasts import timify
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Various forecasting methods implemented as functions."""
|
||||
|
||||
from urban_meal_delivery.forecasts.methods import arima
|
||||
from urban_meal_delivery.forecasts.methods import decomposition
|
||||
from urban_meal_delivery.forecasts.methods import ets
|
||||
|
|
|
@ -14,7 +14,7 @@ def predict(
|
|||
) -> pd.DataFrame:
|
||||
"""Predict with an automatically chosen ARIMA model.
|
||||
|
||||
Note: The function does not check if the `forecast` interval
|
||||
Note: The function does not check if the `forecast_interval`
|
||||
extends the `training_ts`'s interval without a gap!
|
||||
|
||||
Args:
|
||||
|
@ -65,7 +65,7 @@ def predict(
|
|||
forecasts = pandas2ri.rpy2py(result)
|
||||
forecasts.index = forecast_interval
|
||||
|
||||
return forecasts.rename(
|
||||
return forecasts.round(5).rename(
|
||||
columns={
|
||||
'Point Forecast': 'prediction',
|
||||
'Lo 80': 'low80',
|
||||
|
|
|
@ -169,10 +169,13 @@ def stl( # noqa:C901,WPS210,WPS211,WPS231
|
|||
|
||||
# Unpack the result to a `pd.DataFrame`.
|
||||
result = pandas2ri.rpy2py(result[0])
|
||||
result = {
|
||||
'seasonal': pd.Series(result[:, 0], index=time_series.index),
|
||||
'trend': pd.Series(result[:, 1], index=time_series.index),
|
||||
'residual': pd.Series(result[:, 2], index=time_series.index),
|
||||
}
|
||||
result = pd.DataFrame(
|
||||
data={
|
||||
'seasonal': result[:, 0],
|
||||
'trend': result[:, 1],
|
||||
'residual': result[:, 2],
|
||||
},
|
||||
index=time_series.index,
|
||||
)
|
||||
|
||||
return pd.DataFrame(result)
|
||||
return result.round(5)
|
|
@ -14,7 +14,7 @@ def predict(
|
|||
) -> pd.DataFrame:
|
||||
"""Predict with an automatically calibrated ETS model.
|
||||
|
||||
Note: The function does not check if the `forecast` interval
|
||||
Note: The function does not check if the `forecast_interval`
|
||||
extends the `training_ts`'s interval without a gap!
|
||||
|
||||
Args:
|
||||
|
@ -66,7 +66,7 @@ def predict(
|
|||
forecasts = pandas2ri.rpy2py(result)
|
||||
forecasts.index = forecast_interval
|
||||
|
||||
return forecasts.rename(
|
||||
return forecasts.round(5).rename(
|
||||
columns={
|
||||
'Point Forecast': 'prediction',
|
||||
'Lo 80': 'low80',
|
||||
|
|
1
tests/forecasts/methods/__init__.py
Normal file
1
tests/forecasts/methods/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
"""Tests for the `urban_meal_delivery.forecasts.methods` sub-package."""
|
|
@ -7,7 +7,7 @@ import pytest
|
|||
|
||||
from tests.forecasts.conftest import NS
|
||||
from tests.forecasts.conftest import VERTICAL_FREQUENCY
|
||||
from urban_meal_delivery.forecasts import decomposition
|
||||
from urban_meal_delivery.forecasts.methods import decomposition
|
||||
|
||||
|
||||
class TestInvalidArguments:
|
|
@ -1,4 +1,7 @@
|
|||
"""Test the `arima.predict()` and `ets.predict()` functions."""
|
||||
"""Test the `arima.predict()` and `ets.predict()` functions.
|
||||
|
||||
We consider both "classical" time series prediction models.
|
||||
"""
|
||||
|
||||
import datetime as dt
|
||||
|
Loading…
Reference in a new issue