我正在构建我的lstm模型来预测比特币的价格。我有一个问题与预测(x_test)。预测(x_test)的结果应该是2d(维数),but it is kept in a 3d.
How do I get 2d as a result of 'predict(x_test)'?
在我的模型
x_train : (405, 7, 1)
y_train : (405,)
x_test : (103, 7, 1)
y_test : (103, 1)
这是我的代码。
#model create
model = Sequential()
model.add(LSTM(7, return_sequences=True, input_shape=(x_train.shape[1], 1))) # input_shape : (7,1)
model.add(LSTM(10, return_sequences=True))
model.add(Dense(25, activation='relu'))
model.add(Dense(90, activation='relu'))
model.add(Dense(25, activation='relu'))
model.add(Dense(1))
# Compile the model
model.compile(optimizer='adam', loss='mean_squared_error',metrics=['accuracy','mae'])
# Predict
prediction=model.predict(x_test)
prediction.shape
下面是期望的结果:
- 'predict(x_test)'的结果是2d as (103,1)
我试着用google搜索,但是找不到问题。
删除最后一个LSTM层的return_sequences=True
所以你的模型将是:
model = Sequential()
model.add(LSTM(7, return_sequences=True, input_shape=(x_train.shape[1], 1))) # input_shape : (7,1)
model.add(LSTM(10))
model.add(Dense(25, activation='relu'))
model.add(Dense(90, activation='relu'))
model.add(Dense(25, activation='relu'))
model.add(Dense(1))