我正在尝试使用 conv1d 来预测时间序列,但是我在使用 conv1d 输入形状时遇到了问题。我的数据 406 个样本,按时间顺序排列 10 个值。目标是使用样本N作为输入来预测样本N+1。
这是我的代码示例:
data_x = data[:-1]
data_y = data[1:]
print(data_x.shape)
# (406, 10)
print(data_y.shape)
# (406, 10)
data_x = data_x.reshape(-1, 10, 1)
# Shape before cnn : (406, 10, 1)
print('Shape before cnn : ', data_x.shape)
inputs = Input((10, 1))
x = Conv1D(64, 3, input_shape=(10, 1))(inputs)
x = Dense(64, "relu")(x)
x = Dense(64, "relu")(x)
x = Dense(10, "sigmoid")(x)
model = Model(inputs, x)
model.compile(loss='mse', metrics=['mean_squared_error'], optimizer='adam')
history = model.fit(data_x, data_y,
batch_size=22, epochs=EPOCHS)
但我收到此错误 tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [22,10] vs. [22,10,10] [[node mean_squared_error/SquaredDifference (defined at E:/Dev/Python/StockMarketPrevision/mainTensorflow.py:65) ]] [Op:__inference_train_function_872]
。
我不知道我错过了什么。