matlab regiongroups,matlab - Matlab中的神经网络预测数据 - 堆栈内存溢出

我为ANN撰写了一篇有关运输能源需求建模的文章。

我将能源需求作为目标,并输入了3个输入,人口,时速-公里和国民生产总值。 但是,我无法创建多个输入,或者我不知道该怎么做。 在这方面,我寻求您的帮助。

根据这些值,我想训练网络并预测未来5年的需求。

% 1. Importing data

Data_Inputs=xlsread('C:\Users\user\Desktop\FYP\CaseStudy\CaseStudyCol.xlsx'); % Import file

Training_Set1=Data_Inputs(1:end,3);%specific training set

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

Input=Training_Set1'; %Convert to row

Target=Target_Set'; %Convert to row

X = con2seq(Input); %Convert to cell

T = con2seq(Target); %Convert to cell

tr = Data_Inputs(1:end,1);

% 2. Data preparation

N = 5; % 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 = 2;

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.

%[Xs,Xi,Ai,Ts] = preparets(net,inputSeries,{},targetSeries);

[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 = 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');

我尝试使用神经网络工具箱nnstart,并尝试使用应用程序“时间序列工具”。 我尝试加载可用的数据集。 我是否正确定义了输入和目标? 您如何显示呈现预测数据的图形? 训练网络后,回归图在哪里出现? 我怎么知道这是一个好结果?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值