我想一次预测6个月的时间序列。我设置了model.add(Dense(6)),但是它显示了这样的错误。
ValueError:检查输入时出错:预期density_1_input具有 形状(6,),但数组的形状为(1,)
这是我的代码。
df = pd.read_csv('D://data.csv',
engine='python')
df['DATE_'] = pd.to_datetime(df['DATE_']) + MonthEnd(1)
df = df.set_index('DATE_')
df.head()
split_date = pd.Timestamp('03-01-2015')
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:6]
X_test = test_sc[:-1]
y_test = test_sc[1:6]
K.clear_session()
model = Sequential()
model.add(Dense(12, input_dim=6, activation='relu'))
model.add(Dense(6))
model.compile(loss='mean_squared_error', optimizer='adam')
model.summary()
model.fit(X_train, y_train, epochs=200, batch_size=2)
y_pred = model.predict(X_test)
real_pred = sc.inverse_transform(y_pred)
real_test = sc.inverse_transform(y_test)
print("Predict Value")
print(real_pred)
print("Test Value")
print(real_test)