In an effort to add regressors to a multiple-output linear time series model, I'm running into issues combining some data arrays. I have a loop that pulls up to ten time steps to forecast the next twelve timesteps. I have an array of the target variable with shape (60,) and a regressor array with shape (60, 4). After I loop through to add time step lags to my variables, I have the X variable with a shape (39,10), accounting for 39 months with 10 lagging timesteps and the Y variable with shape (39, 12) for 39 months, and the next 12 forecasted time steps.
I would like to try and add 4 additional regressors to this where X would be shape (39, 14) but can't seem to put the two arrays together. Below is code for the data.
import numpy as np
import pandas as pd
sales = np.array([7.95366978, 8.02092772, 8.08517875, 8.04878828, 8.06589355,
8.07496036, 8.11939859, 8.14728826, 8.29579811, 8.10016145,
8.13798045, 8.17216445, 8.28576542, 8.20985248, 8.24590926,
8.17779668, 8.3035048 , 8.25062008, 8.17976049, 8.19560957,
8.20193435, 8.24170316, 8.16280135, 8.20467183, 8.24826745,
8.07651533, 8.22147895, 8.24354551, 8.40290405, 8.24957515,
8.40424843, 8.35819746, 8.53227883, 8.46779284, 8.47449444,
8.51278348, 8.48322267, 8.4854961 , 8.66094716, 8.58783803,
8.59174392, 8.64558641, 8.64646553, 8.66544077, 8.80747189,
8.81269461, 8.52892411, 7.96450336, 9.18911674, 8.7798651 ,
8.83666459, 8.90245559, 8.92572027, 8.8607829 , 8.86827251,
8.83214991, 8.44354665, 8.41693077, 8.452548 , 8.38731227])
promo = np.array([-1., -1., 0., 0., -1., -1., -1., -1., 0., -1., -1., -1., -1.,
-1., 0., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., 0., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., 0., -1., 0., 0., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., -1., -1.])
discount = np.array([ -1., -1., 290., 290., -1., -1., -1., -1., 291., -1., -1.,
-1., -1., -1., 283., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., 57., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,
503., -1., 476., 476., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1.])
discount_days = np.array([-1. , -1. , 26.58333333, 33. , -1. ,
-1. , -1. , -1. , 29. , -1. ,
-1. , -1. , -1. , -1. , 30. ,
-1. , -1. , -1. , -1. , -1. ,
-1. , -1. , -1. , -1. , -1. ,
-1. , -1. , -1. , 6. , -1. ,
-1. , -1. , -1. , -1. , -1. ,
-1. , -1. , -1. , -1. , -1. ,
-1. , -1. , -1. , -1. , 9. ,
-1. , 59. , 59. , -1. , -1. ,
-1. , -1. , -1. , -1. , -1. ,
-1. , -1. , -1. , -1. , -1. ])
s_dict = {'sales':sales,
'discount':promo,
'item_count':item_count,
'days': days}
df_ = pd.DataFrame.from_dict(s_dict)
Here is code to run the model with only 10 lags and no regressors.
T = 10 #number of lags
Ntest = 12 #number of forecasted periods
train = df_.iloc[:-Ntest]
print("train shape:", train.shape)
test = df_.iloc[-Ntest:]
print("test shape:", test.shape)
Tx = T
Ty = Ntest
X = []
Y = []
series = np.array(df_['log_eaches'])
regressors = np.array(df_.iloc[:, 1:])
print("series", np.shape(series), "regressors", np.shape(regressors))
for t in range(len(series) - Tx - Ty + 1):
x = series[t:t+Tx]
print(np.shape(x))
X.append(x)
y = series[t+Tx : t+Tx+Ty]
Y.append(y)
X = np.array(X).reshape(-1, Tx)
Y = np.array(Y).reshape(-1, Ty)
N = len(X)
print(X.shape, Y.shape)
Xtrain_m, Ytrain_m = X[:-1], Y[:-1]
Xtest_m, Ytest_m = X[-1:], Y[-1:]
train_idx = df_.index <= train.index[-1]
test_idx = ~ train_idx
I tried to use np.concatenate but I get a shape error. Does anyone know how to concatenate two arrays so the X variable will have the 4 additional regressors for shape (39,5)?