我有时间序列数据。我尝试重塑并与卷积1D和MaxPooling1D一起使用。
这是我的代码。
#data is time series data splite for train and test
train = df.loc[:split_date, ['data']]
test = df.loc[split_date:, ['data']]
sc = MinMaxScaler()
train_sc = sc.fit_transform(train)
test_sc = sc.transform(test)
X_train = train_sc[:-1]
y_train = train_sc[1:]
X_test = test_sc[:-1]
y_test = test_sc[1:]
################### Convolution #######################
X_train_t = X_train[:, None]
X_test_t = X_test[:, None]
K.clear_session()
model = Sequential()
model.add(Conv1D(6, 1, activation='relu', input_shape=(1,1)))
model.add(MaxPooling1D(pool_size = (3)))
model.add(LSTM(3))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam' )
model.summary()
model.fit(X_train_t, y_train, epochs=400, batch_size=10, verbose=10)
y_pred = model.predict(X_test_t)
real_pred = sc.inverse_transform(y_pred)
real_test = sc.inverse_transform(y_test)
print(real_pred)
print(real_test)
当我运行它时,显示这样的错误。
ValueError:因1减去3而导致的负尺寸大小 输入形状为'max_pooling1d_1 / MaxPool'(op:'MaxPool'): [?,1,1,6]。
我尝试重塑形状,但不起作用。仅当我设置MaxPooling1D(pool_size =(1))时它才起作用。但我认为pool_size不应为1。如何解决?