I am trying an
LSTM model using
tensorflow following this tutorial .
I am having trouble understanding why am I getting an error in my test set when I try to invert scaling for forecast (line 86 in the tutorial).
After loading the dataset and created featured, following is what I did for
# split into train and test sets values = reframed.values split_point = len(reframed)- 168 train = values[ : split_point, :] test = values[split_point: , :] # split into input and outputs train_X, train_y = train[:, :-1], train[:, -1] test_X, test_y = test[:, :-1], test[:, -1] # reshape input to be 3D [samples, timesteps, features] train_X = train_X.reshape((train_X.shape, 1, train_X.shape)) test_X = test_X.reshape((test_X.shape, 1, test_X.shape)) print(train_X.shape, train_y.shape, test_X.shape, test_y.shape) >> (2399, 1, 39) (2399,) (168, 1, 39) (168,) # design network model = Sequential() model.add(LSTM(50, input_shape=(train_X.shape, train_X.shape))) model.add(Dense(1)) model.compile(loss='mae', optimizer='adam') # fit network history = model.fit(train_X, train_y, epochs=50, batch_size=72, validation_data=(test_X, test_y), verbose=2, shuffle=False) # make a prediction yhat = model.predict(test_X) test_X = test_X.reshape((test_X.shape, test_X.shape)) inv_yhat = np.concatenate((yhat, test_X[:, 1:]), axis=1)
After this step, the following code that has
scaler.invert_transform throws the error.
inv_yhat = scaler.inverse_transform(inv_yhat)
ValueError: operands could not be broadcast together with shapes (168,39) (41,) (168,39)
test_X.shape >> (168, 1, 39) yhat.shape >>(168,1) inv_yhat.shape >> (168,39)
Any help or sugeestions would be appreciated!