Using the fastai2 `Datasets` to make an time series dataset.
horizon,lookback = 2,5
ints = L(np.arange(9.)[None,:],np.arange(9.,14)[None,:]).map(tensor)
ints
dl = TSDataLoader(ints, horizon, lookback, step=2, norm=False)
list(dl)
The first sequence (0 to 7) is transformed in to two items. One with x from 0 to 4 and y from 0 to 6.
The next one is shifted just two, because step
== 2.
The second sequence (and third resulting item) is not long enough and is therefore padded with the mean of x (10
). Note both x and y are padded with the mean of x
from fastseq.core import *
from fastai2.basics import *
path = untar_data(URLs.m4_daily)
df_train = pd.read_csv(path/'train.csv',nrows=300)
df_test = pd.read_csv(path/'val.csv')
df_test.head()
horizon = 14
lookback = 14*3
items = ts_lists(df_train.iloc[:,1:].values)
splits = RandomSplitter()(items)
dl = TSDataLoader(items, horizon = horizon, lookback = lookback, step=5)
dl.show_batch()