【问题标题】:Multi-step LSTM Time series prediction多步 LSTM 时间序列预测
【发布时间】: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


【解决方案1】:

问题:我的方法有问题吗?

通常,您可能想尝试多个模型和多个超参数。如果它是一个玩具项目,你至少应该尝试多个模型。在设置参数之前,请确保您了解每个模型的工作原理。

您可能希望输入的数据多于输出的数据。进入 1 小时,预测 10 分钟。

您可能希望在运行任何代码之前进行一些数据分析,以深入了解哪些方法可能有效。使其可视化,创建类似 PCA 的图形(可能不适用于时间序列)。

谈论模型:您可以将 LSTM 替换为 Transformer。它可以将更多信息保留更长时间。这是一种新型模型,在各个方面都优于 LSTM。

如果您对数据科学或机器学习有任何疑问,您应该尝试使用 datascience.StackExchange 而不是 StackOverflow。在这里,我们应该帮助快速、快速地响应代码。 ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2018-09-22
    • 2018-11-16
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 2018-10-07
    相关资源
    最近更新 更多