Title: | Time Series Forecasting Using GRNN |
---|---|
Description: | A general regression neural network (GRNN) is a variant of a Radial Basis Function Network characterized by a fast single-pass learning. 'tsfgrnn' allows you to forecast time series using a GRNN model Francisco Martinez et al. (2019) <doi:10.1007/978-3-030-20521-8_17> and Francisco Martinez et al. (2022) <doi:10.1016/j.neucom.2021.12.028>. When the forecasting horizon is higher than 1, two multi-step ahead forecasting strategies can be used. The model built is autoregressive, that is, it is only based on the observations of the time series. You can consult and plot how the prediction was done. It is also possible to assess the forecasting accuracy of the model using rolling origin evaluation. |
Authors: | Maria Pilar Frias-Bustamante [aut], Ana Maria Martinez-Rodriguez [aut], Antonio Conde-Sanchez [aut], Francisco Martinez [aut, cre] |
Maintainer: | Francisco Martinez <[email protected]> |
License: | GPL-2 |
Version: | 1.0.5 |
Built: | 2024-11-11 03:59:27 UTC |
Source: | https://github.com/franciscomartinezdelrio/tsfgrnn |
It uses an object of class grnnForecast
to create a ggplot
object that
plots a time series and its forecast using GRNN regression.
## S3 method for class 'grnnForecast' autoplot(object, ...)
## S3 method for class 'grnnForecast' autoplot(object, ...)
object |
An object of class |
... |
additional parameter, see details. |
Commonly used parameters are:
highlight
. A character string indicating what elements should be highlighted. Possible values are
"none"
and "points"
. The default value is "none"
.
The ggplot
object representing a plotting with the forecast.
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12, sigma = 50) library(ggplot2) autoplot(pred)
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12, sigma = 50) library(ggplot2) autoplot(pred)
It shows the examples of the model associated to a
grnnForecast
object.
grnn_examples(forecast)
grnn_examples(forecast)
forecast |
A |
A matrix including the features and targets of the examples
associated with the model of a grnnForecast
object.
pred <- grnn_forecasting(ts(1:8), h = 1, lags = 1:2) grnn_examples(pred)
pred <- grnn_forecasting(ts(1:8), h = 1, lags = 1:2) grnn_examples(pred)
It applies GRNN regression to forecast the future values of a time series.
The lags used as autoregressive variables are set with the lags
parameter. If the user does not set the lags, these values are selected
automatically.
grnn_forecasting( timeS, h, lags = NULL, sigma = "ROLLING", msas = c("recursive", "MIMO"), transform = c("additive", "multiplicative", "none") )
grnn_forecasting( timeS, h, lags = NULL, sigma = "ROLLING", msas = c("recursive", "MIMO"), transform = c("additive", "multiplicative", "none") )
timeS |
A numeric vector or time series of class |
h |
A positive integer. Number of periods for forecasting. |
lags |
An integer vector in increasing order expressing the lags used as
autoregressive variables. If NULL (the default) the lags are selected in a
fast, heuristic way. It is also possible to use the values |
sigma |
A positive real value or a character value. The smoothing parameter in GRNN regression. Two character values are possible, "ROLLING" (the default) and "FIXED", in which case the parameter is chosen using an optimization tool with rolling origin evaluation or fixed origin evaluation. |
msas |
A string indicating the Multiple-Step Ahead Strategy used when more than one value is predicted. It can be "MIMO" or "recursive" (the default). |
transform |
A character value indicating whether the training samples
are transformed. If the time series has a trend it is recommended. By
default is |
An object of class "grnnForecast"
. The function
summary
can be used to obtain or print a summary of the
results. An object of class "gnnForecast"
is a list containing at
least the following components:
call |
the matched call. |
msas |
the Multi-Step Ahead Strategy. |
prediction |
a time series with the forecast. |
model |
an object of class |
F. Martinez et al. (2022). "Strategies for time series forecasting with generalized regression neural networks", Neurocomputing, 491, pp. 509–521.
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12) plot(pred)
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12) plot(pred)
It shows the input vector and the weights of the training examples used in a prediction associated with a "grnnForecast" object.
grnn_weights(forecast)
grnn_weights(forecast)
forecast |
A |
A list including the input vectors used in GRNN regression and the training examples, with their weights, used in the prediction.
pred <- grnn_forecasting(UKgas, h = 4, lags = 1:4, msas = "MIMO") grnn_weights(pred)
pred <- grnn_forecasting(UKgas, h = 4, lags = 1:4, msas = "MIMO") grnn_weights(pred)
This function is useful to see how the forecast has been computed. An ordinal specifying the order of the weight has to be supplied and the function plots the training pattern associated with that ordinal.
plot_example(forecast, position, h = 1)
plot_example(forecast, position, h = 1)
forecast |
The grnnForecast object. |
position |
An integer. It is an ordinal number indicating what training
pattern to plot. For instance, if |
h |
An integer. This value is only useful when the recursive strategy is being used. It indicates the forecasting horizon |
A ggplot object representing an example used in the prediction.
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12, sigma = 50) library(ggplot2) plot_example(pred, 1)
pred <- grnn_forecasting(USAccDeaths, h = 12, lags = 1:12, sigma = 50) library(ggplot2) plot_example(pred, 1)
It plots the forecast associated with a test set generated with the function
rolling_origin
.
## S3 method for class 'grnnForecastRO' plot(x, h = NULL, ...)
## S3 method for class 'grnnForecastRO' plot(x, h = NULL, ...)
x |
the object obtained from a call to |
h |
an integer. The forecasting horizon. If |
... |
Other plotting parameters to affect the plot. |
None
Predicted values based on a GRNN model for time series forecasting.
## S3 method for class 'grnnForecast' predict(object, h, ...)
## S3 method for class 'grnnForecast' predict(object, h, ...)
object |
a |
h |
an integer. The forecasting horizon. |
... |
further arguments passed to or from other methods. |
If the models uses the MIMO strategy for multiple-step ahead prediction, the forecasting horizon is fixed to the model forecasting horizon.
a grnnForecast
object with the prediction and information
about the GRNN model, see the documentation of grnn_forecasting
for the structure of grnnForecast
objects.
pred <- grnn_forecasting(UKgas, h = 4, msas = "MIMO") new_pred <- predict(pred, h = 4) print(new_pred$prediction) plot(new_pred) # To see a plot with the forecast
pred <- grnn_forecasting(UKgas, h = 4, msas = "MIMO") new_pred <- predict(pred, h = 4) print(new_pred$prediction) plot(new_pred) # To see a plot with the forecast
It uses the model and the time series associated with a grnnForecast
object to assess the forecasting accuracy of the model using the last
h
values of the time series to build test sets applying a rolling
origin evaluation.
rolling_origin(grnnf, h = NULL, rolling = TRUE)
rolling_origin(grnnf, h = NULL, rolling = TRUE)
grnnf |
A |
h |
A positive integer. The forecast horizon. If |
rolling |
A logical. If |
This function assesses the forecast accuracy of the model used by the
grnnForecast
object. It uses h
different test and training
sets. The first test set consists of the last h
values of the time
series (the training set is formed by the previous values). The next test set
consists of the last values of the time series and so on (the
last test set is formed by the last value of the time series).
A list containing at least the following fields:
test_sets |
a matrix containing the test sets used in the evaluation. Every row contains a different test set. |
predictions |
The predictions for the test sets. |
errors |
The errors for the test sets. |
global_accu |
Different measures of accuracy applied to all the errors. |
h_accu |
Different measures of accuracy applied to all the errors for every forecasting horizon. |
pred <- grnn_forecasting(UKgas, h = 4, lags = 1:4) ro <- rolling_origin(pred) print(ro$global_accu)
pred <- grnn_forecasting(UKgas, h = 4, lags = 1:4) ro <- rolling_origin(pred) print(ro$global_accu)