How to perform multi-step ahead forecasting with LSTM. I want to predict 2,3, and 4 time stesp ahead prediction with LSTM?
Please help. Thanks in advance.

2 件のコメント

Nikolaos Efkarpidis
Nikolaos Efkarpidis 2021 年 1 月 13 日
Dear,
How did you finally perform multi-step ahead forecasting with LSTM and predictAndUpdateState ?
I am also struggling with this issue.
Best regards,
Nick
Raziye Ghasemi
Raziye Ghasemi 2023 年 11 月 22 日

How did you finally perform multi-step ahead forecasting with LSTM and predictAndUpdateState ? I am also struggling with this issue.

サインインしてコメントする。

 採用された回答

adel adel
adel adel 2020 年 5 月 25 日

2 投票

Forecasting is basicaly sequence-to-sequence regression, let suppos that your entire sequence is data,
1. You divide data into train and test parts, you can specify the proportion as you wish:
numTimeStepsTrain = floor(0.9*numel(data));% 90% for training 10%for testing
dataTrain = data(1:numTimeStepsTrain+1);
dataTest = data(numTimeStepsTrain+1:end);
2. Preparing training data and response sequences by shifting data by one time step, such as for data(t) the response will be data(t+1)
XTrain = dataTrain(1:end-1);
YTrain = dataTrain(2:end);
3. Preparing the network and training hyperparameters, then train the network using training data and training responses
numFeatures = 1;
numResponses = 1;
numHiddenUnits = 200;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',250, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
3. Now you can forecast 1, 2, 3 or 4 steps ahead using predictAndUpdateState function, since you use predicted values to update the network state and you don’t use actual values contained in dataTest for this, you can make predictions on any time step number
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTrain(end));
stepsAhead = 4; % you can use 1,2,3,4 on any value of steps ahead
for i = 2:stepsAhead+1
[net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1));
end

4 件のコメント

anurag kulshrestha
anurag kulshrestha 2020 年 5 月 30 日
Thanks. But your code is preciting only 4 steps ahead. I have a test set with 30 data points (lets assume). This code is using only the one predicted value to generate one step ahead predicitons. But, if i want to utilize past 2 or 3 or 4 predicted values to generate one step ahead forecasting like mutli-step? WIll this code work?
Aniroodh Kumaraswamy
Aniroodh Kumaraswamy 2022 年 3 月 28 日
Very valid question, I too am confused how multiple historical values can be used (say 10 values) to get a forecast into the future. Would appreciate a response from someone who knows
Gordon Elgin
Gordon Elgin 2023 年 8 月 25 日
I have a question. I know that you can predict multi-time steps. However, how do we input say 5 timesteps to predict 1 time step ahead.
Kapila
Kapila 2023 年 11 月 2 日
Any answer for this?

サインインしてコメントする。

その他の回答 (1 件)

David Willingham
David Willingham 2022 年 3 月 28 日

1 投票

Hi,
Please see this updated example in R2022a that shows multi-step ahead (closed loop) predictions:

2 件のコメント

Shawn Berry
Shawn Berry 2022 年 3 月 28 日
Thanks!
nahed zemouri
nahed zemouri 2023 年 6 月 19 日
thanks

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by