Suppose that DD
is a time series data (one column and X
rows). I separate 11 samples from end of data as out-of-sample and train neural network by MATLAB. The performance of neural network is good in train, test and validation data (default properties of fitting app neural network: fitnet
).
for ii = 31 : (numel(DD)-1)
D_0(ii-30,1) = DD(ii-0);
D_1(ii-30,1) = DD(ii-1);
D_2(ii-30,1) = DD(ii-2);
D_3(ii-30,1) = DD(ii-3);
D_4(ii-30,1) = DD(ii-4);
D_5(ii-30,1) = DD(ii-5);
D_6(ii-30,1) = DD(ii-6);
D_7(ii-30,1) = DD(ii-7);
D_14(ii-30,1) = DD(ii-14);
D_30(ii-30,1) = DD(ii-30);
D_plus_1(ii-30,1) = DD(ii+1);
end
x = [D_0 D_1 D_2 D_3 D_4 D_5 D_6 D_7 D_14 D_30]';
t = D_plus_1';
%% Out-of-sample data
x_oos = x(:,end-10:end);
t_oos = t(:,end-10:end);
x(:,end-10:end) = [];
t(:,end-10:end) = [];
hiddenLayerSize = 5;
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
net = fitnet(hiddenLayerSize,trainFcn);
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean Squared Error
[net,tr] = train(net,x,t);
x
is input of neural network and t
is output(target) of neural network. After training i used this code to predict results for out of sample data:
y_Out = net(x_oos);
This is comparison between real and predicted output of out-of-sample data:
But i think there is a lag between two outputs. Now check this with one step lag:
Why we have this behavior in out-of-sample data? I checked different time lengths of out-of-sample and we have same behavior (one step lag). Is this data behavior?
PS.
All data (x
variable as input of trained net and comparing with t
variable) as input of trained neural network:
There is a lag between all data as input!. Neural network trained with this lag in data! Is this a bug?! this is a daily time series for near two years without any missing data.