# How to predict future values with LSTM (RNN)?

조회 수: 9(최근 30일)
Ful0 2021년 3월 26일
편집: Ful0 2021년 4월 1일
Hello everyone,
Can anyone explain me how to predict future values with LSTM?
I would like to compare the prediction of a NARXNET and a LSTM net, but I can't understand from the matlab examples how to train an LSTM network with one input (11000 value of water demand) and one different output(11000 values of energy consumption). Once I train the net, I should be able to find 500 new values of energy consumption if I give to the net 500 new value of water demand.
Can anyone help me with this issue, please?
Thank you so much
Ful
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Ful0 2021년 3월 31일
편집: Ful0 2021년 3월 31일
Hello Sir,
I just change my network in order to simulate the example presents in Matlab Documentation, but with my data. It is not anymore what I ask in my previous question, but I try to make it simpler.
I want to forecast the hourly water demand in a water system. My data are over 15 mouths.
Below my code:
start_toolkit;
d=epanet('Prova reti neurali_15 mesi_ONOFF.inp');
A=d.getComputedTimeSeries;
% Portata utenza
portata_utenze = A.Demand(:,1);
data = portata_utenze';
figure (1)
plot(data)
xlabel("h")
ylabel("Portata [l/s]")
title("Portata richiesta dalla utenza")
numTimeStepsTrain = floor(0.9*numel(data));
dataTrain = data(1:numTimeStepsTrain+1);
dataTest = data(numTimeStepsTrain+1:end);
mu = mean(dataTrain);
sig = std(dataTrain);
dataTrainStandardized = (dataTrain - mu) / sig;
XTrain = dataTrainStandardized(1:end-1);
YTrain = dataTrainStandardized(2:end);
numFeatures = 1;
numResponses = 1;
numHiddenUnits = 200;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
'MaxEpochs',100, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
dataTestStandardized = (dataTest - mu) / sig;
XTest = dataTestStandardized(1:end-1);
numTimeStepsTest = numel(XTest);
for i = 2:numTimeStepsTest
end
YPred = sig*YPred + mu;
YTest = dataTest(2:end);
rmse = sqrt(mean((YPred-YTest).^2))
figure (2)
plot(dataTrain(1:end-1))
hold on
idx = numTimeStepsTrain:(numTimeStepsTrain+numTimeStepsTest);
plot(idx,[data(numTimeStepsTrain) YPred],'.-')
hold off
xlabel("h")
ylabel("Portata [l/s]")
title("Previsione")
legend(["Reali" "Previsti"])
figure (3)
subplot(2,1,1)
plot(YTest)
hold on
plot(YPred,'.-')
hold off
legend(["Reali" "Previsti"])
ylabel("Portata [l/s]")
title("Previsione")
subplot(2,1,2)
stem(YPred - YTest)
xlabel("h")
ylabel("Error")
title("RMSE = " + rmse)
I can't understand why the figures aren't similar to the ones in the example.
Below my figure (3)

댓글을 달려면 로그인하십시오.

### 답변(1개)

Gaurav Garg 2021년 4월 1일
Hi,
Since the input dataset and models used by you and examples in MATLAB are different, you are expected to see different results.
Moreover, RMSE results plotted by you are not the way they should be. Kindly look at the following link for more info on RMSE.
##### 댓글 수: 1표시숨기기 없음
Ful0 2021년 4월 1일
편집: Ful0 2021년 4월 1일
I don't understand what are the errors in my code.
Why it can't predict 3 weeks of water demand if the net is trained using 60 weeks of water demand past values?
Thank's for the link suggested, but it doesn't help me to find the error in my previous code.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Deep Learning with Time Series and Sequence Data in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by