File Exchange

image thumbnail

Time Series Prediction

version 1.3.0 (4.34 KB) by Abolfazl Nejatian
time series prediction by use of Deep learning and shallow learning algorithm


Updated 08 Dec 2018

View License

Time Series Prediction,
by use of Deep learning Bi-Long Short Memory (bi-LSTM) Network
And shallow learning simple Feedforward Network.
input data should be an excel file with one column.
I’ve to Thank my dear friend Dr. S.Mostapha Kalami Heris for his
code in “PlotResults” function.

If you have questions or would like to improve the code, don't hesitate
to mail me:

Best wishes,
Abolfazl Nejatian
23 Nov 2018

Cite As

Abolfazl Nejatian (2020). Time Series Prediction (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (24)

Aman Swaraj

I faced a problem
Reference to non-existent field 'XTs'.

Error in timeSeriesPrediction_1>evaluateNet (line 275)
TestOutputs = (predict(results.Net,data.XTs,'MiniBatchSize',opt.miniBatchSize));

Error in timeSeriesPrediction_1 (line 72)
results = evaluateNet(results,data,opt);

What about the forecasting data? where could i see those?


Same question as Ali, please include the xlsx sample data file. It's missing in the zip downlaod. Thanks!

The code is nice - as mentioned before the calculation of mean and std should be applied only to train data. It could also be improved by adding selectable multiple steps ahead predictions capability into general parameters section of the code.

Hi, I'm begginer in Matlab.
How I can use the code to forecast the future time series? I can read test data, but I want find 10-12 future series.

in 'results' variable I see only compare beetween targets and outputs for test data.

FengJin jin

Hello, the following error occurred while I was running

The function or variable 'sequenceInputLayer' is not defined.

Error LSTMArchitect (line 14)

Error main4 (line 44)
Opt = LSTMArchitect(opt);

Dong Yao

weiwei duan

Hello, I feel the code needs to be
changed. It seems that it can read the test data and tune the model accordingly. It should not be in a practical case.

Abolfazl is a nice and helping person. He tries to help with the code.


Dear Abolfazl,
Thank you for sharing the code, but i have a problem when trying to run it, i have this error massage :
Struct contents reference from a non-struct array object.

Error in timeSeriesPrediction (line 44)
if ~data.isDataRead
could you help please.
thanks in advance


data file (.xlsx) ? Can anyone upload data file as a reference?

i discussed the code with other experts and I can confirm that Victor Plaza is right. The code assumes that the mean and deviation for test set is known, which is not possible and unsuitable for a real-time forecasting

I think your code is biased from the beginning. You are normalizing the data previously to split it into training and testing.
That implies you know the mean and the standard deviation of the testing set, what is false. You need to calculate these measures for the training set, what is what you will have in online processing, and later apply it to the testing set.
Calculating them over the whole data set allows the LSTM to access data that is actually unavailable.


Dear Abolfazl,

Thank you for posting this code. I have a question regarding the possibility of multistep ahead predictions using this code.
I see that the delays can be used to train the LSTM on several step ahead data. The test set is also prepared in a similar manner. It seems that the predictions are N- step ahead where N would be max(Delays)+1. But when i observe the results in my case, it does not seem to be the case.

I would kindly request you to give an interpretation (with respect to prediction horizon) for the plot showing 'all data'.

I have a time series with of length 720 samples with 30 sec interval between two consecutive samples. I am basically trying to: (i) get predictions for one hour ahead (ii) given the time series, predict 'n' further steps of that series.

Thank you for your time!

dear @Eduardo Santos
by downloading the updated code, you can find output data on the workspace in 'results' variable.
best wishes
Abolfazl Nejatian

How may I see the forecast data? I mean... How do interpret the script output data?



save outputs data on the workspace.
fix some minor bugs.


fix some minor bugs


fix some minor bogs

MATLAB Release Compatibility
Created with R2018b
Compatible with R2018a to R2018b
Platform Compatibility
Windows macOS Linux