MATLAB Answers

0

Predicting one period ahead using neural networks

Danielle Leblance さんによって質問されました 2017 年 12 月 6 日
最新アクティビティ Greg Heath
さんによって 回答されました 2017 年 12 月 8 日
Hi, I have prices and i am trying to predict next period's price using neural network. I found a code on Mathworks website and modified it (the data is attached). However, i am failing to predict one period ahead because the code is generating errors that are the differences between real data and the model data for the validation data. I am using neural networks for the first time and i don't know how to generate the forecast for the next period (last day in the sample is 28th july 2017 and i want to predict the price of 29th of July 2017) any help is greatly appreciated
close all, clear all, clc, format compact
load Data0
% data settings
N = length(Price)*0.70; % number of samples
Nu = length(Price)*0.30; % number of learning samples
% prepare training data
yt = con2seq(Price(1:Nu)');
% prepare validation data
yv = con2seq(Price(Nu+1:end)');
inputDelays = 3;
hiddenSizes =2;
% nonlinear autoregressive neural network
net = narnet(inputDelays, hiddenSizes);
[Xs,Xi,Ai,Ts] = preparets(net,{},{},yt);
%%Prepare input and target time series data for network training
% [Xs,Xi,Ai,Ts,EWs,shift] = preparets(net,Xnf,Tnf,Tf,EW)
%
% This function simplifies the normally complex and error prone task of
% reformatting input and target timeseries. It automatically shifts input
% and target time series as many steps as are needed to fill the initial
% input and layer delay states. If the network has open loop feedback,
% then it copies feedback targets into the inputs as needed to define the
% open loop inputs.
%
% net : Neural network
% Xnf : Non-feedback inputs
% Tnf : Non-feedback targets
% Tf : Feedback targets
% EW : Error weights (default = {1})
%
% Xs : Shifted inputs
% Xi : Initial input delay states
% Ai : Initial layer delay states
% Ts : Shifted targets
[Xs,Xi,Ai,Ts] = preparets(net,{},{},yt);
% train net with prepared training data
net = train(net,Xs,Ts,Xi,Ai);
% close feedback for recursive prediction
net = closeloop(net);
%%Recursive prediction on validation data
% prepare validation data for network simulation
yini = yt(end-max(inputDelays)+1:end); % initial values from training data
% combine initial values and validation data 'yv'
[Xs,Xi,Ai] = preparets(net,{},{},[yini yv]);
% predict on validation data
predict = net(Xs,Xi,Ai);
% validation data
Yv = cell2mat(yv);
% prediction
Yp = cell2mat(predict);
% error
e = Yv - Yp;

  0 件のコメント

サインイン to comment.

1 件の回答

Greg Heath
回答者: Greg Heath
2017 年 12 月 8 日

You do not understand the basics regarding the use of
1. training/validation/testing data division
2. Significant delays determined from the auto and cross correlation functions.
3. Necessary and sufficient number of hidden nodes
Please see my tutorials and posts in the NEWSGROUP and ANSWERS
greg narx
greg narxnet
Hope this helps
Greg

  0 件のコメント

サインイン to comment.



Translated by