Monday, 11 November 2019

Recurrent neural networks for Time Series with Multiple Variables - TensorFlow

I'm using previous demand to predict future demand, using 3 variables, but whenever I run the code my Y axis shows error

If I use only one variable on the Y axis separately it has no error.

Example:

demandaY = bike_data[['cnt']]
n_steps = 20

for time_step in range(1, n_steps+1):
    demandaY['cnt'+str(time_step)] = demandaY[['cnt']].shift(-time_step).values

y = demandaY.iloc[:, 1:].values
y = np.reshape(y, (y.shape[0], n_steps, 1))

DATASET

enter image description here

SCRIPT

features = ['cnt','temp','hum']
demanda = bike_data[features]
n_steps = 20

for var_col in features:
    for time_step in range(1, n_steps+1):
        demanda[var_col+str(time_step)] = demanda[[var_col]].shift(-time_step).values

demanda.dropna(inplace=True)
demanda.head()

n_var = len(features)
columns = list(filter(lambda col: not(col.endswith("%d" % n_steps)), demanda.columns))

X = demanda[columns].iloc[:, :(n_steps*n_var)].values
X = np.reshape(X, (X.shape[0], n_steps, n_var))

y = demanda.iloc[:, 0].values
y = np.reshape(y, (y.shape[0], n_steps, 1))

OUTPUT

ValueError: cannot reshape array of size 17379 into shape (17379,20,1)

GitHub: repository



from Recurrent neural networks for Time Series with Multiple Variables - TensorFlow

No comments:

Post a Comment