ptrblck:

Do you know, if it needs to have a specific shape, e.g. for preprocessing purposes, or could it be dynamic?


@ptrblck  In the repository  the code is hard coded.  actually they  mentioned it in their  repository description
​ The model is evaluated on the electricity dataset, which contains the electricity consumption of 370 households from 2011 to 2014. Under hourly frequency, we use the first week of September, 2014 as the test set and all time steps prior to that as the train set. Following the experiment design in DeepAR, the window size is chosen to be 192, where the last 24 is the forecasting horizon. History (number of time steps since the beginning of each household), month of the year, day of the week, and hour of the day are used as time covariates. Notice that some households started at different times, so we only use windows that contain non-missing values. for better understanding  the original preprocess.py was like this
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os
from datetime import datetime, timedelta
import pandas as pd
import math
import numpy as np
import random
from tqdm import trange

from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile

from math import sqrt
from pandas import read_csv, DataFrame
from scipy import stats

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

def prep_data(data, covariates, data_start, train = True):
    #print("train: ", train)
    time_len = data.shape[0]
    #print("time_len: ", time_len)
    input_size = window_size-stride_size
    windows_per_series = np.full((num_series), (time_len-input_size) // stride_size)
    #print("windows pre: ", windows_per_series.shape)
    if train: windows_per_series -= (data_start+stride_size-1) // stride_size
    #print("data_start: ", data_start.shape)
    #print(data_start)
    #print("windows: ", windows_per_series.shape)
    #print(windows_per_series)
    total_windows = np.sum(windows_per_series)
    x_input = np.zeros((total_windows, window_size, 1 + num_covariates + 1), dtype='float32')
    label = np.zeros((total_windows, window_size), dtype='float32')
    v_input = np.zeros((total_windows, 2), dtype='float32')
    #cov = 3: ground truth + age + day_of_week + hour_of_day + num_series
    #cov = 4: ground truth + age + day_of_week + hour_of_day + month_of_year + num_series
    count = 0
    if not train:
        covariates = covariates[-time_len:]
    for series in trange(num_series):
        cov_age = stats.zscore(np.arange(total_time-data_start[series]))
        if train:
            covariates[data_start[series]:time_len, 0] = cov_age[:time_len-data_start[series]]
        else:
            covariates[:, 0] = cov_age[-time_len:]
        for i in range(windows_per_series[series]):
            if train:
                window_start = stride_size*i+data_start[series]
            else:
                window_start = stride_size*i
            window_end = window_start+window_size
            '''
            print("x: ", x_input[count, 1:, 0].shape)
            print("window start: ", window_start)
            print("window end: ", window_end)
            print("data: ", data.shape)
            print("d: ", data[window_start:window_end-1, series].shape)
            '''
            x_input[count, 1:, 0] = data[window_start:window_end-1, series]
            x_input[count, :, 1:1+num_covariates] = covariates[window_start:window_end, :]
            x_input[count, :, -1] = series
            label[count, :] = data[window_start:window_end, series]
            nonzero_sum = (x_input[count, 1:input_size, 0]!=0).sum()
            if nonzero_sum == 0:
                v_input[count, 0] = 0
            else:
                v_input[count, 0] = np.true_divide(x_input[count, 1:input_size, 0].sum(),nonzero_sum)+1
                x_input[count, :, 0] = x_input[count, :, 0]/v_input[count, 0]
                if train:
                    label[count, :] = label[count, :]/v_input[count, 0]
            count += 1
    prefix = os.path.join(save_path, 'train_' if train else 'test_')
    np.save(prefix+'data_'+save_name, x_input)
    np.save(prefix+'v_'+save_name, v_input)
    np.save(prefix+'label_'+save_name, label)

def gen_covariates(times, num_covariates):
    covariates = np.zeros((times.shape[0], num_covariates))
    for i, input_time in enumerate(times):
        covariates[i, 1] = input_time.weekday()
        covariates[i, 2] = input_time.hour
        covariates[i, 3] = input_time.month
    for i in range(1,num_covariates):
        covariates[:,i] = stats.zscore(covariates[:,i])
    return covariates[:, :num_covariates]

def visualize(data, week_start):
    x = np.arange(window_size)
    f = plt.figure()
    plt.plot(x, data[week_start:week_start+window_size], color='b')
    f.savefig("visual.png")
    plt.close()

if __name__ == '__main__':

    global save_path
    name = 'LD2011_2014.txt'
    save_name = 'elect'
    window_size = 192
    stride_size = 24
    num_covariates = 4
    train_start = '2011-01-01 00:00:00'
    train_end = '2014-08-31 23:00:00'
    test_start = '2014-08-25 00:00:00' #need additional 7 days as given info
    test_end = '2014-09-07 23:00:00'
    pred_days = 7
    given_days = 7

    save_path = os.path.join('data', save_name)
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    csv_path = os.path.join(save_path, name)
    if not os.path.exists(csv_path):
        zipurl = 'https://archive.ics.uci.edu/ml/machine-learning-databases/00321/LD2011_2014.txt.zip'
        with urlopen(zipurl) as zipresp:
            with ZipFile(BytesIO(zipresp.read())) as zfile:
                zfile.extractall(save_path)

    data_frame = pd.read_csv(csv_path, sep=";", index_col=0, parse_dates=True, decimal=',')
    data_frame = data_frame.resample('1H',label = 'left',closed = 'right').sum()[train_start:test_end]
    data_frame.fillna(0, inplace=True)
    covariates = gen_covariates(data_frame[train_start:test_end].index, num_covariates)
    train_data = data_frame[train_start:train_end].values
    test_data = data_frame[test_start:test_end].values
    data_start = (train_data!=0).argmax(axis=0) #find first nonzero value in each time series
    total_time = data_frame.shape[0] #32304
    num_series = data_frame.shape[1] #370
    prep_data(train_data, covariates, data_start)
    prep_data(test_data, covariates, data_start, train=False)


this   store both. train and test files i eg: data/elect/ train.npy ,data/elect/ test.npy   total  stored files was 6.
If I  am wrong please try to correct me that for my case I am feeling that it needs to be dynamic here . About the test_window ,  I have seen it  hard_coded in  params.json file . I also  pass different number instead of 192  it can predict
but the prediction is  always showing  24 hours prediction. for  both of the case . I expected that  the test window 5 will show only the prediction of 5 hours
testwindow_51350×574 53.2 KB
the output is like this
      y_true      y_pred  ...     y2_lower     y2_upper

0   6.686744e+06  85177600.0  … -576900544.0  747255744.0
1   4.888917e+06  90021016.0  … -571470784.0  751512768.0
2   1.507870e+07  92519352.0  … -567632768.0  752671488.0
3   1.824654e+07  94020880.0  … -564585664.0  752627392.0
4   7.327324e+06  94660928.0  … -562476416.0  751798272.0
5   2.968790e+07  94579640.0  … -561239040.0  750398336.0
6   1.234428e+08  93913760.0  … -560794624.0  748622208.0
7   3.505584e+08  92788040.0  … -561048960.0  746625024.0
8   7.173911e+08  91309272.0  … -561905984.0  744524480.0
9   1.000136e+09  89564064.0  … -563277312.0  742405504.0
10  9.772118e+08  87619696.0  … -565085632.0  740325056.0
11  6.443588e+08  85526472.0  … -567264640.0  738317568.0
12  2.442418e+08  83321008.0  … -569757248.0  736399296.0
13  5.765772e+08  81029616.0  … -572512256.0  734571520.0
14  6.966076e+08  78671512.0  … -575480512.0  732823488.0
15  8.396323e+08  76261480.0  … -578611904.0  731134912.0
16  9.348614e+08  73811656.0  … -581854080.0  729477376.0
17  3.790162e+08  71332320.0  … -585151872.0  727816576.0
18  7.515996e+08  68831560.0  … -588451200.0  726114304.0
19  4.156775e+08  66314284.0  … -591702528.0  724331136.0
20  2.908992e+08  63780448.0  … -594867968.0  722428800.0
21  1.801725e+08  61223460.0  … -597925888.0  720372864.0
22  5.370657e+07  58629428.0  … -600874496.0  718133376.0
23  1.840954e+07  55977044.0  … -603732288.0  715686336.0
[24 rows x 6 columns]