Using Neural networks to predict new data

9 次查看(过去 30 天)
Hello, Can someone help please?
I have model:
1 predictor : 34163 x 1 matrix
target output: 34163 x 1 matrix
I would like to use the same model to predict another target output2: 34163 x 1 matrix
I used this command:
>> Y = sim(net,output2')
Error using network/sim
Number of inputs does not match net.numInputs.
below is the function genarate by MATLAB for the for the model:
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 14-Jul-2023 10:59:43
%
% This script assumes these variables are defined:
%
% input - input time series.
% output - feedback time series.
X = tonndata(input,false,false);
T = tonndata(output,false,false);
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer
% states. Using PREPARETS allows you to keep your original time series data
% unchanged, while easily customizing it for networks with differing
% numbers of delays, with open loop or closed loop feedback modes.
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotresponse(t,y)
%figure, ploterrcorr(e)
%figure, plotinerrcorr(x,e)
% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the output layer.
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)
% Step-Ahead Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is
% given y(t+1). For some applications such as decision making, it would
% help to have predicted y(t+1) once y(t) is available, but before the
% actual y(t+1) occurs. The network can be made to return its output a
% timestep early by removing one delay so that its minimal tap delay is now
% 0 instead of 1. The new network returns the same outputs as the original
% network, but outputs are shifted left one timestep.
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)
  3 个评论
Sanley Guerrier
Sanley Guerrier 2023-7-14
移动:the cyclist 2023-7-14
This file contains the input and the output data. Thanks!

请先登录,再进行评论。

回答(1 个)

Saarthak Gupta
Saarthak Gupta 2023-8-24
Hi Sanley,
The neural network expects two inputs - an input time series (x(t)) and a feedback time series (y(t)). You may confirm the same by visualising the network:
view(net);
To correctly simulate the network, you need to provide both inputs as a Ni-by-TS matrix where Ni is the number of inputs and TS is the number of time steps (2 and 34163 respectively, in your case). Hence the correct command for simulation would be:
Y = sim(net, [input output2]');
You may refer to the documentation of the sim command, or type help network/sim in the MATLAB command window for more information about the sim command.

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by