我确实编写了代码来尝试为多元时间序列建立预测模型。编写代码非常困难,每次都会出错,但是我做到了。无论如何,在我的代码中,我没有在model.fit
中添加validation_data
。现在,当我添加部分代码时出错!
我把代码留给你。我希望有人能理解我的validation_ data.
我有一张表,该表包含52行(这是2017年的52周)和要研究时间序列的1018个项目。这是一张表格,解释了商店中不同商品在2017年的销售量。我用39时间坐火车。
# normalizzazione :
scaler= MinMaxScaler(feature_range=(-1,1))
scaled= scaler.fit_transform(tabartset_clu) # i dati che sono int32 vengono convertiti in un float 64
scaled=pd.DataFrame(scaled)
# creo il training set e il target set e il test set ( necessario per la validazione)
train_clu, valid_clu = train_test_split(scaled, test_size=0.25)
train_clu_y= scaled.iloc[13:52, :] test= scaled.iloc[39:52, :]
test_X, test_Y= test.iloc[:, :-1], test.iloc[:, -1]
test_X= np.array(test_X)
test_X_= test_X.reshape(test_X.shape[0],1,test_X.shape[1])
# disegno la rete neurale
train_clu=np.array(train_clu)
train_clu_y= np.array(train_clu_y)
train_clu_y = train_clu_y.reshape(1, 39, 1018) # per poter fare il reshape devo trasformare il mio dataframe in array
train_clu = train_clu.reshape(1, 39,1018)
# create LSTM
model = Sequential()
model.add(LSTM(1018, input_shape=(39,1018), return_sequences=True))
model.add(ks.layers.Dropout(0.2))
model.add(ks.layers.TimeDistributed(Dense(1018)))
model.add(ks.layers.Dropout(0.2))
model.add(ks.layers.Activation('linear'))
model.compile(loss='mean_squared_error', optimizer='adam')
print('######################### model.summary() ##########################')
print(model.summary())
print('######################### FITMODEL TRAIN ##########################')
valid_clu=np.array(valid_clu)
val_sha= valid_clu.reshape(13,1,1018)
history= model.fit(train_clu, train_clu_y, epochs=80,validation_data=(test_X_, test_Y), batch_size=1, verbose=2, shuffle=False)
print('fatto fitting')
# evaluate
result = model.predict(train_clu, batch_size=1, verbose=2)
print (train_clu.shape) (39, 1018)
print (valid_clu.shape) (13, 1018)
print (train_clu_y.shape) (39, 1018)
print (training.shape) (39, 1018)
print (test.shape) (13,1018)
print (test_X.shape) (13,1017)
print(test_X_.shape) (13,1,1017)
print(test_Y.shape) (13,)
错误是:ValueError:检查输入时出错:预期lstm_1_input具有形状(39,1018),但数组的形状为(1,1017)
谢谢!一切都很好的想法