训练后如何让我的LSTM模型预测

时间:2019-05-28 13:12:06

标签: python keras deep-learning lstm prediction

我是ML的初学者,我正在使用LSTM模型来预测列的未来值,我认为我在训练模型时成功了,但我正在努力使模型预测未来值 我的数据集是这样的:    c0 c1 c2 c3 c4 c5  0.953202 0.998825 0.943329 0.762738 0.046798 0.0 .... 我训练了模型以根据其他列预测c5的值


# split into train and test sets
values = reframed.values
n_train_hours = 24*24
train = values[:n_train_hours, :]
test = values[n_train_hours:, :]

# split into input and outputs
train_X, train_y = train[:, :-1], train[:, -1]
test_X, test_y = test[:, :-1], test[:, -1]
# reshape input to be 3D [samples, timesteps, features]
train_X = train_X.reshape((train_X.shape[0], 1, train_X.shape[1]))
test_X = test_X.reshape((test_X.shape[0], 1, test_X.shape[1]))
print(train_X.shape, train_y.shape, test_X.shape, test_y.shape, try1.shape)

# design network
model = Sequential()
model.add(LSTM(50, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dense(1))
model.compile(loss='mae', optimizer='adam')
# fit network
history = model.fit(train_X, train_y, epochs=50, batch_size=72, validation_data=(test_X, test_y), verbose=2, shuffle=False)

# make a prediction
      ???

2 个答案:

答案 0 :(得分:0)

您可以使用模型进行以下预测:

print(model.predict('''your sample'''))

这将打印预测的标签。

答案 1 :(得分:0)

要查看预测:

model.predict(test_X)

要计算测试数据的即时性和损失:

model.evaluate(test_X,test_Y)

您可以在https://keras.io/models/model/

中找到有关模型方法的所有信息