How to forecast with Neural Network?

G
Goryn · Jul 29, 2021 · 2.2K views
Question
I'm using MATLAB R2011a. I'm trying to predict next 100 points of time-serie X by means of neural net. Firstly, I create input time series Xtra and feedback time series Ytra:     lag = 50; Xu = windowize(X,1:lag+1); %Re-arrange the data points into a Hankel matrix Xtra = Xu(:,1:lag); %input time series Ytra = Xu(:,end); %feedback time series Then I train neural net with this code: inputSeries = tonndata(Xtra,false,false); targetSeries = tonndata(Ytra,false,false); % Create a Nonlinear Autoregressive Network with External Input inputDelays = 1:2; feedbackDelays = 1:2; hiddenLayerSize = 10; net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize); % Prepare the Data for Training and Simulation [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) And then I would like to predict next 100 points of my initial time-serie X, what should I do?
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 24, 2026
0. Incorrect use of the word 'lag'
 
1. It is rare that the default input parameters (ID,FD,H) are sufficient. They can be improved by using a subset of significant lags determined from the auto and cross-correlation functions and then searching over a range of H values. The smallest acceptable value of H should be used.
 
2. The default 'dividerand' should be overwritten (e.g., 'divideblock') to optimize the effectiveness of the significant correlation lags found in 1.
 
3. Train using the syntax
 
 [net tr Ys Es Xf Af ] = train(net,Xs,Ts,Xi,Ai);
to use Xf and Af as intial conditions for continuation data
 
4. After closing the loop, test the CL net on the original data. If performance is not good compared to the OL performance, train the CL net beginning with the weights obtained with the OL training.
 
5. Since you only have 1 series, you should have used NARNET. To continue beyond the original data
Xnew = net(NaN(1,100),Xf,Af);
 
 
 
Here is the example

Electricity Load Forecasting in MATLAB

The electricity power consumption is a non-linear process. Artificial Neural Networks have the capability to predict future data based on the data fed for training as it can recognize the pattern in it. This will in turn enable us to maintain a good power management..

https://www.matlabsolutions.com/matlab-projects/electricity-load-forecasting-using-neural-network-in-matlab.php

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!