I have 1002 times of observing the 10 features. I have concatenated together for doing preprocessing on the data and now, I need to reshape it to a 3D input data to be used in LSTM. I do not know using pd.df.groupby(['timestep'])
is meaningful but I have used a tiny "np.reshape"
function but seems does not determine and I got the error. The code is below:
train_dataset = dataset.sample(frac=0.8,random_state=0)
test_dataset = dataset.drop(train_dataset.index)
scaler = MinMaxScaler()
train_x = scaler.fit_transform(train_dataset)
test_x = scaler.fit_transform(test_dataset)
data_train = train_x.reshape(1002, 1001, 11)
def build_model():
model = tf.keras.Sequential([
layers.LSTM(128,activation=tf.nn.relu,input_shape=train_dataset.shape[1:],return_sequences=True, return_state=True),
layers.LSTM(128,activation=tf.nn.relu,return_sequences=True, return_state=True),
layers.Dense(1)
])
opt = tf.keras.optimizers.Adam(learning_rate=0.001)
model.compile(loss='mean_squared_error', optimizer=opt, metrics= ['mean_squared_error','mean_absolute_error'])
return model
and the error that I faced for the Dense layer
is below:
Input 0 of layer lstm_10 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 11]