mlp: Multilayer Perceptron for time series forecasting

View source: R/mlp.R

mlpR Documentation

Multilayer Perceptron for time series forecasting

Description

This function fits MLP neural networks for time series forecasting.

Usage

mlp(
  y,
  m = frequency(y),
  hd = NULL,
  reps = 20,
  comb = c("median", "mean", "mode"),
  lags = NULL,
  keep = NULL,
  difforder = NULL,
  outplot = c(FALSE, TRUE),
  sel.lag = c(TRUE, FALSE),
  allow.det.season = c(TRUE, FALSE),
  det.type = c("auto", "bin", "trg"),
  xreg = NULL,
  xreg.lags = NULL,
  xreg.keep = NULL,
  hd.auto.type = c("set", "valid", "cv", "elm"),
  hd.max = NULL,
  model = NULL,
  retrain = c(FALSE, TRUE),
  ...
)

Arguments

y

Input time series. Can be ts or msts object.

m

Frequency of the time series. By default it is picked up from y.

hd

Number of hidden nodes. This can be a vector, where each number represents the number of hidden nodes of a different hidden layer.

reps

Number of networks to train, the result is the ensemble forecast.

comb

Combination operator for forecasts when reps > 1. Can be "median", "mode" (based on KDE estimation) and "mean".

lags

Lags of y to use as inputs. If none provided then 1:frequency(y) is used. Use 0 for no univariate lags.

keep

Logical vector to force lags to stay in the model if sel.lag == TRUE. If NULL then it keep = rep(FALSE,length(lags)).

difforder

Vector including the differencing lags. For example c(1,12) will apply first and seasonal (12) differences. For no differencing use 0. For automatic selection use NULL.

outplot

Provide plot of model fit. Can be TRUE or FALSE.

sel.lag

Automatically select lags. Can be TRUE or FALSE.

allow.det.season

Permit modelling seasonality with deterministic dummies.

det.type

Type of deterministic seasonality dummies to use. This can be "bin" for binary or "trg" for a sine-cosine pair. With "auto" if ony a single seasonality is used and periodicity is up to 12 then "bin" is used, otherwise "trg".

xreg

Exogenous regressors. Each column is a different regressor and the sample size must be at least as long as the target in-sample set, but can be longer.

xreg.lags

This is a list containing the lags for each exogenous variable. Each list is a numeric vector containing lags. If xreg has 3 columns then the xreg.lags list must contain three elements. If NULL then it is automatically specified.

xreg.keep

List of logical vectors to force lags of xreg to stay in the model if sel.lag == TRUE. If NULL then all exogenous lags can be removed. The syntax for multiple xreg is the same as for xreg.lags.

hd.auto.type

Used only if hd==NULL. "set" fixes hd=5. "valid" uses a 20% validation set (randomly) sampled to find the best number of hidden nodes. "cv" uses 5-fold cross-validation. "elm" uses ELM to estimate the number of hidden nodes (experimental).

hd.max

When hd.auto.type is set to either "valid" or "cv" then this argument can be used to set the maximum number of hidden nodes to evaluate, otherwise the maximum is set automatically.

model

A previously trained mlp object. If this is provided then the same model is fitted to y, without re-estimating any model parameters.

retrain

If a previous model is provided, retrain the network or not.

...

Additional inputs for neuralnet function.

Value

Return object of class mlp. The function plot produces a plot the network architecture. mlp contains:

  • net - MLP networks.

  • hd - Number of hidden nodes.

  • lags - Input lags used.

  • xreg.lags - xreg lags used.

  • difforder - Differencing used.

  • sdummy - Use of deterministic seasonality.

  • ff - Seasonal frequencies detected in data (taken from ts or msts object).

  • ff.det - Seasonal frequencies coded using deterministic dummies.

  • det.type - Type of determistic seasonality.

  • y - Input time series.

  • minmax - Scaling structure.

  • xreg.minmax - Scaling structure for xreg variables.

  • comb - Combination operator used.

  • fitted - Fitted values.

  • MSE - In-sample Mean Squared Error.

  • MSEH - If hd.auto.type is set to either "valid" or "cv" an array of the MSE error for each network size is provided. Otherwise this is NULL.

Note

To use mlp with Temporal Hierarchies (thief package) see mlp.thief.

Author(s)

Nikolaos Kourentzes, nikolaos@kourentzes.com

References

See Also

forecast.mlp, mlp.thief, elm.

Examples


## Not run: 
 fit <- mlp(AirPassengers)
 print(fit)
 plot(fit)
 frc <- forecast(fit,h=36)
 plot(frc)

## End(Not run)


trnnick/nnfor documentation built on Nov. 12, 2023, 9:45 p.m.