keras python-lstm:model.fit我必须在validation_data中添加哪些数据提示?

时间:2018-11-15 16:08:11

标签: python tensorflow keras lstm recurrent-neural-network

我确实编写了代码来尝试为多元时间序列建立预测模型。编写代码非常困难,每次都会出错,但是我做到了。无论如何,在我的代码中,我没有在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)

谢谢!一切都很好的想法

0 个答案:

没有答案