I am doing an LSTM based model with data sets. I used the standardization method to put my data in the interval (0, 1) like this:
scaler = MinMaxScaler(feature_range=(0, 1))
scaler = scaler.fit(df_train)
df_train = scaler.transform(df_train)
df_test = scaler.transform(df_test)
Just after the standardization, I reshape my data to obtain:
x_train (3125, 50, 5)
y_train (3125, 1)
x_test (1000, 50, 5)
y_test (1000, 1)
The model works and I get predictions, but when I want to inverse_transform
my data I get the following error:
yhat = model.predict(x_test)
yhat = scaler.inverse_transform(yhat)
ValueError: non-broadcastable output operand with shape (1000,1) doesn't match the broadcast shape (1000,5)
So I tried this sample code by changing the name corresponding to my variables:
yhat = model.predict(test_X)
test_X = test_X.reshape((test_X.shape[0], test_X.shape[2]))
# invert scaling for forecast
inv_yhat = concatenate((yhat, test_X[:, 1:]), axis=1)
inv_yhat = scaler.inverse_transform(inv_yhat)
inv_yhat = inv_yhat[:,0]
# invert scaling for actual
test_y = test_y.reshape((len(test_y), 1))
inv_y = concatenate((test_y, test_X[:, 1:]), axis=1)
inv_y = scaler.inverse_transform(inv_y)
inv_y = inv_y[:,0]
# calculate RMSE
rmse = sqrt(mean_squared_error(inv_y, inv_yhat))
print('Test RMSE: %.3f' % rmse)
but I get this error in line 2:
ValueError: cannot reshape array of size 250000 into shape (1000,5)