Install

PyPI

pip install utilsforecast

Conda

conda install -c conda-forge utilsforecast

How to use

Generate synthetic data

from utilsforecast.data import generate_series
series = generate_series(3, with_trend=True, static_as_categorical=False)
series
unique_iddsy
002000-01-010.422133
102000-01-021.501407
202000-01-032.568495
302000-01-043.529085
402000-01-054.481929
48122000-06-11163.914625
48222000-06-12166.018479
48322000-06-13160.839176
48422000-06-14162.679603
48522000-06-15165.089288

Plotting

from utilsforecast.plotting import plot_series
fig = plot_series(series, plot_random=False, max_insample_length=50, engine='matplotlib')
fig.savefig('imgs/index.png', bbox_inches='tight')

Preprocessing

from utilsforecast.preprocessing import fill_gaps
serie = series[series['unique_id'].eq(0)].tail(10)
# drop some points
with_gaps = serie.sample(frac=0.5, random_state=0).sort_values('ds')
with_gaps
unique_iddsy
21302000-08-0118.543147
21402000-08-0219.941764
21602000-08-0421.968733
22002000-08-0819.091509
22102000-08-0920.220739
fill_gaps(with_gaps, freq='D')
unique_iddsy
002000-08-0118.543147
102000-08-0219.941764
202000-08-03NaN
302000-08-0421.968733
402000-08-05NaN
502000-08-06NaN
602000-08-07NaN
702000-08-0819.091509
802000-08-0920.220739

Evaluating

from functools import partial

import numpy as np

from utilsforecast.evaluation import evaluate
from utilsforecast.losses import mape, mase
valid = series.groupby('unique_id').tail(7).copy()
train = series.drop(valid.index)
rng = np.random.RandomState(0)
valid['seas_naive'] = train.groupby('unique_id')['y'].tail(7).values
valid['rand_model'] = valid['y'] * rng.rand(valid['y'].shape[0])
daily_mase = partial(mase, seasonality=7)
evaluate(valid, metrics=[mape, daily_mase], train_df=train)
unique_idmetricseas_naiverand_model
00mape0.0241390.440173
11mape0.0542590.278123
22mape0.0426420.480316
30mase0.90714916.418014
41mase0.9916356.404254
52mase1.01359611.365040