【发布时间】:2021-09-08 21:47:44
【问题描述】:
我正在尝试为多步预测构建 LSTM 模型。我的数据是每五分钟采样一次的停车占用率时间序列(我有 25 周的样本)。我开始创建如下代码:
import numpy as np
training_data_len = int(np.ceil( len(data) * .90 ))
train_data = data.iloc[0:int(training_data_len), :]
print(len(train_data))
# Create the testing data set
test_data = data.iloc[training_data_len: , :] # - timestep
print(len(test_data))
data_train = np.array(train_data)
def split_sequence(sequence, n_steps_in, n_steps_out):
X, y = list(), list()
for i in range(len(sequence)):
# find the end of this pattern
end_ix = i + n_steps_in
out_end_ix = end_ix + n_steps_out
# check if we are beyond the sequence
if out_end_ix > len(sequence):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequence[i:end_ix], sequence[end_ix:out_end_ix]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
X_train, y_train = [], []
X_train, y_train = split_sequence(data_train,6,6)
reg = Sequential()
reg.add(LSTM(units = 200,return_sequences=True, input_shape=(1,1)))#, return_sequences=True , activation = 'relu'
reg.add(Dropout(0.2))
reg.add(LSTM(units = 200,return_sequences=True)) #, activation = 'relu'
reg.add(Dropout(0.2))
reg.add(LSTM(units = 200,return_sequences=True)) #, activation = 'relu'
reg.add(Dropout(0.2))
reg.add(Dense(6,))
#here we have considered loss as mean square error and optimizer as adam
reg.compile(loss='mse', optimizer='adam')
#training the model
#,validation_split=0.1,
# shuffle=False
reg.fit(X_train, y_train, epochs = 10,verbose=1)
data_test = np.array(test_data)
#here we are splitting the data weekly wise(7days)
X_test, y_test = split_sequence(data_test,6,6)
y_pred = reg.predict(X_test)
我的目标是使用过去 30 分钟(6 个样本 =30 分钟)预测接下来的 30 分钟(6 个样本 =30 分钟)。
我是这些模型的新手,我想知道我是否工作得很好,或者有什么我遗漏或改进的地方。 谢谢
【问题讨论】:
-
问题是什么? (编辑标题)有什么问题?如果它有效,那么(如果我错了,请原谅我)但我相信 Stackoverflow 可能不是要问的确切地方,但无论如何我会尽力提供帮助,因为我是一个反叛者! :)
-
抱歉,我正在尝试了解我的方法是否适合多步任务
标签: python time-series lstm prediction multi-step