Error NARX Model Prediction

2 次查看(过去 30 天)
Seda
Seda 2024-3-2
评论: Seda 2024-4-18
Hello everyone...
Im doing a carbon emission(output) with multiple input using neural network approached (NARX). I trained the model using NARX tollbox. I couldn't find the code I needed to write to predict the next 8 years. It doesn't give any predictions in the code I wrote... Would you mind to help me ? Where is the mistake :( My code;
x=xlsread('Input.xlsx');
t=xlsread('Output.xlsx');
X = tonndata(x,false,false);
T = tonndata(t,false,false);
trainFcn = 'trainlm';
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t] = preparets(net,X,{},T);
net.divideParam.trainRatio = 80/100;
net.divideParam.valRatio = 10/100;
net.divideParam.testRatio = 10/100;
[net,tr] = train(net,x,t,xi,ai);
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
view(net)
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc)
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
numFutureSteps = 8;
predictedValues = cell(1, numFutureSteps);
[~, lastInputState, lastLayerState] = preparets(netc, X, {}, T);
lastOutput = yc{end};
for i = 1:numFutureSteps
[nextOutput, nextInputState, nextLayerState] = netc({lastOutput}, lastInputState, lastLayerState);
predictedValues{i} = nextOutput;
lastOutput = nextOutput;
lastInputState = nextInputState;lastLayerState = nextLayerState;
  3 个评论
Seda
Seda 2024-4-18
First of all, thank you very much for your return.
I didn't get an error. I'm just not sure if my codes are correct.
Seda
Seda 2024-4-18
Is the code I use to predict the future correct? @Shivansh

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by