This function fits MLP neural networks for time series forecasting.
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), ...)
Input time series. Can be ts or msts object.
Frequency of the time series. By default it is picked up from y.
Number of hidden nodes. This can be a vector, where each number represents the number of hidden nodes of a different hidden layer.
Number of networks to train, the result is the ensemble forecast.
Combination operator for forecasts when reps > 1. Can be "median", "mode" (based on KDE estimation) and "mean".
Lags of y to use as inputs. If none provided then 1:frequency(y) is used. Use 0 for no univariate lags.
Logical vector to force lags to stay in the model if sel.lag == TRUE. If NULL then it keep = rep(FALSE,length(lags)).
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.
Provide plot of model fit. Can be TRUE or FALSE.
Automatically select lags. Can be TRUE or FALSE.
Permit modelling seasonality with deterministic dummies.
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".
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.
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.
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.
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).
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.
A previously trained mlp object. If this is provided then the same model is fitted to y, without re-estimating any model parameters.
If a previous model is provided, retrain the network or not.
Additional inputs for neuralnet function.
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.
For an introduction to neural networks see: Ord K., Fildes R., Kourentzes N. (2017) Principles of Business Forecasting 2e. Wessex Press Publishing Co., Chapter 10.
For combination operators see: Kourentzes N., Barrow B.K., Crone S.F. (2014) Neural network ensemble operators for time series forecasting. Expert Systems with Applications, 41(9), 4235-4244.
For variable selection see: Crone S.F., Kourentzes N. (2010) Feature selection for time series prediction <U+2013> A combined filter and wrapper approach for neural networks. Neurocomputing, 73(10), 1923-1936.
# NOT RUN {
fit <- mlp(AirPassengers)
print(fit)
plot(fit)
frc <- forecast(fit,h=36)
plot(frc)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab