# How to Use Neural Networks to Forecast Time Series Data with Predictor Variables?

I have browsed a lot of topics here, but the ones I see were all about forecasting a single variable, depending on its historical values. Whereas I want to predict a variable, by estimating a relationship between multiple predictor variables as well.

So I'm trying to find a function $f(x_1,x_2, ... , x_p) = y$

-How- Can I apply a neural network approach for such a task?

If not, what alternatives can I use for this?

## Edit :

I am trying to implement this in MATLAB, so I would really appreciate some MATLAB implementation of such methods.

you should consider a matrix of samples $X\in \mathbb R^{n\times p}$ where each column is a different variable and each rows is a different samples that is a discrete representation of your time series. After that you can train a neural network with input $X$ and output $y$ as if it is a simple polynomial interpolation.

The problem is actually more complex but this could probably be a starting point

• Thanks, so what will y be? just an empty matrix of size n x p ? – jeff Aug 29 '14 at 21:32
• no $y$ is your output vector. When you do polynomial interpolation you have an input $X$ and an output $y$. In this case it is the same. Usually $y\in \mathbb{R}^n$ – Donbeo Aug 29 '14 at 21:33
• Oh, so it is what I want. Great, thanks. Can you please provide some MATLAB implementation ? – jeff Aug 29 '14 at 23:01
• In matlab run nftool this will provide a GUI that and instructions to create your model – Donbeo Aug 30 '14 at 3:50

In the feedforward case, the function form is given by the following equation. $$f(a_{t-1}, a_{t-2}, .., a_{t-n}, b_{t-1}, b_{t-2},..b_{t-b}) = y_t$$

The design matrix in the space of an observations by features matrix is the column-wise concatenation of the individual autoregressive design matrices. In R, this is cbind. In Python, this is hstack. In Octave, this is horzcat.

this is textbook.

Here is narxnet from MathWorks. http://www.mathworks.com/help/nnet/ref/narxnet.html

narxnet is nonlinear autoregressive with exogenous (extra) variables. Each of the inputs is a time series.

Best of luck.

You can use univariate (or multivariate) time series regressions or neural network. Neural networks are more powerful, especially the dynamic NN which have memory and they can be trained to learn sequential or time-varying patterns. In contrast to regression models, you can train your neural network model by setting different parameters (and the training algorithm to use) and then check its quality on a test set (or on the actual set of points you are trying to predict if you have it!). A crucial step is the setting of the n. of delay and the n. of the hidden neurons of the NN. An increase of them would reduce the Mean Squared Error but it would increase the computational time of the algorithm. So, it is necessary to find a right trade-off between them.

Furthermore, to start and get used to training NN, check out this applet:

https://nl.mathworks.com/help/nnet/gs/neural-network-time-series-prediction-and-modeling.html

or otherwise open the Neural Network Start GUI with this command:

nnstart

It is an easy way to train your NN and it gives you the scripts at the end!