【问题标题】:What are the Inputs, Outputs and Target in ANNANN中的输入、输出和目标是什么
【发布时间】:2013-12-07 20:20:40
【问题描述】:

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

我正在使用此代码进行预测,但它无法预测未来,谁能帮我再次修复它?谢谢。

%% 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');

【问题讨论】:

    标签: matlab artificial-intelligence neural-network prediction


    【解决方案1】:

    输入和目标是您用于训练网络的数据。 输入和目标已知正确数据。在您完成训练网络后,您再次发送仅输入,您的输出将根据您在训练课程中发送的输入和目标进行预测.因此,您的目标将是您已经知道的数据的正确输出

    据我所知,您正在尝试预测未来,而您只有日期?如果我错了,请纠正我。所以在这种情况下:

    训练前:

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

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

    ..train(net, input, target..
    

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

    【讨论】:

    • 感谢您的评论。通常,我们可以使用历史数据来预测未来。例如,我有 1992-2012 年的降雨量和水位数据。现在我需要预测2015年的水位,那一年的水位与关口相比如何。这就像天气预报,但这里是针对水位的。如果您有一些代码,请也提供给我。谢谢
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      • 2013-11-04
      • 1970-01-01
      • 2017-07-10
      • 2020-08-04
      相关资源
      最近更新 更多