Neural networks can also be used to generate forecasts for a time series variable. There is a library called forecast
in R that deploys feed-forward neural networks with a single hidden layer, and lagged inputs for forecasting univariate time series. For the forecasting example, we have taken an inbuilt dataset available in R called "Air Passengers" to apply the neural network.
The following table reflects the parameter arguments required by the nnetar
function with the corresponding description of how they are being used in the model:
|
Univariate time series with a time variable |
|
Number of non-seasonal lags used as input |
|
Number of seasonal lags used as input |
|
Number of nodes in the hidden layer |
|
Number of networks to fit with different random settings of weights |
|
This is known as box-cox transformation parameter |
|
External regressors used in fitting the model |
|
Point forecasts as mean |
The actual time series looks as follows:
> fit<-nnetar(AirPassengers, p=9,P=,size = 10, repeats = 50,lambda = 0) > plot(forecast(fit,10))
A neural-network-based forecasting model generates the following results as an output:
> summary(fit) Length Class Mode x 144 ts numeric m 1 -none- numeric p 1 -none- numeric P 1 -none- numeric scale 1 -none- numeric size 1 -none- numeric lambda 1 -none- numeric model 50 nnetarmodels list fitted 144 ts numeric residuals 144 ts numeric lags 10 -none- numeric series 1 -none- character method 1 -none- character call 6 -none- call
With a forecast of the next 10 periods, the graph looks as follows:
3.139.107.210