temperature forecast using nn

4 visualizaciones (últimos 30 días)
rabi darji
rabi darji el 17 de Mayo de 2017
Editada: Greg Heath el 19 de Mayo de 2017
i am doing temperature forecasting. my inputs having 12 set of columns and 1796 of rows which is past 5 years of temp. data. I want to forecast the temperature of next day data by giving the input parameter which is date. so my model will give the output max temp, min temp and avg temp. i did training and testing part and i got R=.89 after test. so after that what i should have to do i want to know? i am giving you the code below
% Solve an Autoregression Problem with External Input with a NARX Neural Network % Script generated by NTSTOOL % Created Wed May 17 20:33:44 IST 2017 % % This script assumes these variables are defined: % % input - input time series. % target - feedback time series.
inputSeries = tonndata(input,false,false); targetSeries = tonndata(target,false,false);
% Create a Nonlinear Autoregressive Network with External Input inputDelays = 1:2; feedbackDelays = 1:2; hiddenLayerSize = 10; net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
% Choose Input and Feedback Pre/Post-Processing Functions % Settings for feedback input are automatically applied to feedback output % For a list of all processing functions type: help nnprocess % Customize input parameters at: net.inputs{i}.processParam % Customize output parameters at: net.outputs{i}.processParam net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% 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 % The function DIVIDERAND randomly assigns target values to training, % validation and test sets during training. % For a list of all data division functions type: help nndivide net.divideFcn = 'dividerand'; % Divide data randomly % The property DIVIDEMODE set to TIMESTEP means that targets are divided % into training, validation and test sets according to timesteps. % For a list of data division modes type: help nntype_data_division_mode net.divideMode = 'value'; % Divide up every value net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
% Choose a Training Function % For a list of all training functions type: help nntrain % Customize training parameters at: net.trainParam net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function % For a list of all performance functions type: help nnperformance % Customize performance parameters at: net.performParam net.performFcn = 'mse'; % Mean squared error
% Choose Plot Functions % For a list of all plot functions type: help nnplot % Customize plot parameters at: net.plotParam net.plotFcns = {'plotperform','plottrainstate','plotresponse', ... 'ploterrcorr', 'plotinerrcorr'};
% 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)
% Recalculate Training, Validation and Test Performance trainTargets = gmultiply(targets,tr.trainMask); valTargets = gmultiply(targets,tr.valMask); testTargets = gmultiply(targets,tr.testMask); trainPerformance = perform(net,trainTargets,outputs) valPerformance = perform(net,valTargets,outputs) testPerformance = perform(net,testTargets,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)
  1 comentario
John D'Errico
John D'Errico el 17 de Mayo de 2017
Editada: John D'Errico el 17 de Mayo de 2017
Please learn to format your code. As it is, your code is unreadable. There may be lines of code in there among the comments, but I had to work to find them.
Read this:
https://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099
If you want help, then make it easy for someone to help you.

Iniciar sesión para comentar.

Respuestas (1)

Greg Heath
Greg Heath el 17 de Mayo de 2017
1. For N "O"-dimensional "O"utput target vectors corresponding to N "I"-dimensional "I"nput column vectors, the size of the data matrices are
[ I N ] = size(input)
[ O N ] = size(target)
[ O N ] = size(output)
Are the following correct?
I = 12, N = 1975, O = 3
2. The only timeseries data division function that yields UNBIASED PREDICTIONS of validation and test data is
divideFcn = divideblock
where all of the nontraining data occurs AFTER the training data.
3. Performance improvement usually entails
a. Using some of the statistically sufficient feedback lags of the
12*3 = 36 input-target cross-correlation functions
b. Searching over several non-default numbers of hidden nodes.
4. I have posted zillions of NARXNET examples in both the NEWSREADER and ANSWERS. Most of the tutorials types are in the NEWSREADER.
Hope this helps.
Thank you for formally accepting my answer
Greg
  2 comentarios
rabi darji
rabi darji el 18 de Mayo de 2017
i am beginner in matlab. i tried a lot to understand from your newsgroup but i failed. So requesting you to kindly provide me the full code.
Greg Heath
Greg Heath el 19 de Mayo de 2017
Editada: Greg Heath el 19 de Mayo de 2017
No. I have posted more than enough material for you to figure it out.
If you have intelligent questions, post them and someone will probably help.
Greg

Iniciar sesión para comentar.

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by