1 回答
TA贡献1898条经验 获得超8个赞
units是 的第一个参数LSTM,表示该层输出数据的最后一个维度。它显示第一个错误,因为您的代码units在您的第一次尝试中没有。units满足条件,以便在第二次尝试中显示第二个错误。
input_shape在这种情况下,您应该使用该参数来指定第一层输入的形状。您的第一LSTM层input_shape应该有两个数据(timestepand feature,batch_size默认情况下不需要填写),因为 LSTM 需要三维输入。假设您的时间步长为 10,您的代码应更改为以下内容。
from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import Dense, LSTM, Dropout,Activation
model = Sequential()
model.add(LSTM(units=100,input_shape=(10,1),return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(100, return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(units=1))
model.add(Activation('linear'))
model.compile(loss="mse", optimizer="rmsprop")
print(model.summary())
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm (LSTM) (None, 10, 100) 40800
_________________________________________________________________
dropout (Dropout) (None, 10, 100) 0
_________________________________________________________________
lstm_1 (LSTM) (None, 100) 80400
_________________________________________________________________
dropout_1 (Dropout) (None, 100) 0
_________________________________________________________________
dense (Dense) (None, 1) 101
_________________________________________________________________
activation (Activation) (None, 1) 0
=================================================================
Total params: 121,301
Trainable params: 121,301
Non-trainable params: 0
_________________________________________________________________
添加回答
举报