我已经在MATLAB中使用以下代码训练了NARX网络。我想从新输入(testX)和目标(testY)测试训练有素的网络。但是我在最后一行中得到错误forecastLoad = sim(net,testX&# 39)&#39 ;;
X = tonndata(trainX,false,false);
T = tonndata(trainY,false,false);
inputSeries = X;
targetSeries = T;
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:3;
feedbackDelays = 1:3;
hiddenLayerSize = 20;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
% Prepare the Data for Training and Simulation
% The function PREPARETS prepares time series data
[inputs,inputStates,layerStates,targets] = ...
preparets(net,inputSeries,{},targetSeries);
% Set up 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,inputs,targets,inputStates,layerStates);
%%
% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
MAE = mae(errors);
%Test on new data
forecastLoad = sim(net, testX')';
error = testY-forecastLoad;
答案 0 :(得分:1)
看看Matlab测试数据线:
% Test the Network
outputs = net(inputs,inputStates,layerStates);
为什么不以同样的方式输入数据?让我们这样做:
% Prepare first the data.
[inputs,inputStates,layerStates,targets] = ...
preparets(net,textX,{},testY);
% And then predict.
forecastLoad = net(inputs,inputStates,layerStates);