ANN中的输入,输出和目标是什么

时间:2013-11-22 20:06:28

标签: matlab artificial-intelligence neural-network prediction

我对输入数据集,输出和目标感到困惑。我正在研究Matlab中的人工神经网络,我的目的是希望使用历史数据(我有20年前的降雨和水位)来预测未来的水位(例如2014年)。那么,我的输入,目标和输出在哪里?例如,我有一个Excel工作表数据为[Column1-Date |第2栏 - 降雨量|第3栏|水位]

我正在使用此代码进行预测,但未来无法预测,是否有人可以帮我修复它?谢谢。

%% 1. Importing data
Data_Inputs=xlsread('demo.xls'); % Import file

Training_Set=Data_Inputs(1:end,2);%specific training set

Target_Set=Data_Inputs(1:end,3); %specific target set

Input=Training_Set'; %Convert to row

Target=Target_Set'; %Convert to row

X = con2seq(Input); %Convert to cell

T = con2seq(Target); %Convert to cell

%% 2. Data preparation

N = 365; % Multi-step ahead prediction

% Input and target series are divided in two groups of data:
% 1st group: used to train the network

inputSeries  = X(1:end-N);

targetSeries = T(1:end-N);

inputSeriesVal  = X(end-N+1:end);

targetSeriesVal = T(end-N+1:end); 
% Create a Nonlinear Autoregressive Network with External Input
delay = 2;
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);

% 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.

[inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);

% 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,inputs,targets,inputStates,layerStates);

% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% View the Network
view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotregression(targets,outputs)
%figure, plotresponse(targets,outputs)
%figure, ploterrcorr(errors)
%figure, plotinerrcorr(inputs,errors)

% Closed Loop Network
% Use this network to do multi-step prediction.
 % The function CLOSELOOP replaces the feedback input with a direct
% connection from the outout layer.
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc)
[xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(netc,tc,yc)

% Early 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,inputSeries,{},targetSeries);
ys = nets(xs,xis,ais);
earlyPredictPerformance = perform(nets,ts,ys)

%% 5. Multi-step ahead prediction

inputSeriesPred  = [inputSeries(end-delay+1:end),inputSeriesVal];

targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];

[Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred);

yPred = netc(Xs,Xi,Ai);

perf = perform(net,yPred,targetSeriesVal);

figure;

plot([cell2mat(targetSeries),nan(1,N);
  nan(1,length(targetSeries)),cell2mat(yPred);
  nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]')

legend('Original Targets','Network Predictions','Expected Outputs');

2 个答案:

答案 0 :(得分:3)

输入和目标是您用于训练网络的数据。 输入和定位正确 已知的数据。拥有经过培训的网络后,您再次发送仅输入,并根据您在培训课程中发送的输入和目标预测输出 。因此,对于您已经知道的数据,目标将是正确的输出

据我所知,你正在试图预测未来和未来你只有约会吗?如果我错了,请纠正我。所以在这种情况下:

培训前:

input1 = date; input2 = rainFall;
input = [input1; input2];
target = waterLevel;

因为你想从网上取回水位的结果,你的目标也应该是水位。 现在你训练网;

..train(net, input, target..

培训结束后 现在正如你所说,你想要预测水位,但你只给出了日期,例如2015-11-11,所以在这种情况下它是不可能的,因为你需要降雨信息,所以如果你还想要根据你需要预测降雨量的日期来预测你的水位,或者消除它,因为当你不再知道它时它没有帮助。

答案 1 :(得分:0)

我会说你的输入是降雨量和水位,目标是下一年的水位,输出是预测的水位。

换句话说,在培训时,您的输入应为rainfall(k-2:k-1)(直接输入)和waterlevel(k-2:k-1)(作为反馈)。您的目标是waterlevel(k)。这应该输出一年kwaterlevel_hat(k))的水位估算值。您可以计算错误e = waterlevel_hat(k) - waterlevel(k)并使用它来训练网络。您应该对所有k > 2重复相同的过程(原因是您有2个输入延迟和2个反馈延迟)。