A feature that was missing in the nnfor package was the ability to reuse and retrain mlp and elm model fits. This is now possible with the new arguments model
and retrain
.
As an example, let us use the AirPassengers time series, with three different sample sizes and re-use and re-train the same model in various combinations.
library(nnfor) # Get some data y <- AirPassengers y1 <- window(y,end=c(1958,12)) y2 <- window(y,end=c(1959,12)) y3 <- window(y,end=c(1960,12)) # Fit NN fit <- list() fit[[1]] <- mlp(y1) fit[[2]] <- mlp(y2,model=fit[[1]]) fit[[3]] <- mlp(y2,model=fit[[1]],retrain=TRUE) fit[[4]] <- mlp(y3,model=fit[[1]]) fit[[5]] <- mlp(y3,model=fit[[3]]) fit[[6]] <- mlp(y3,model=fit[[1]],retrain=TRUE) fit[[7]] <- mlp(y3) # Get MSE and number of lags mse <- unlist(lapply(fit,function(x){x$MSE})) lags <- unlist(lapply(fit,function(x){length(x$lags)})) round(mse,2) lags
Model | Series Sample | Training Sample | Retrain | MSE | Lags |
---|---|---|---|---|---|
fit[[1]] | up to 1958 | up to 1958 | X | 6.73 | 9 |
fit[[2]] | up to 1958 | up to 1958 | 61.25 | 9 | |
fit[[3]] | up to 1959 | up to 1959 | X | 6.68 | 9 |
fit[[4]] | up to 1960 | up to 1958 | 541.13 | 9 | |
fit[[5]] | up to 1960 | up to 1959 | 260.22 | 9 | |
fit[[6]] | up to 1960 | up to 1960 | X | 12.65 | 9 |
fit[[7]] | up to 1960 | up to 1960 | New fit | 7.95 | 10 |
As you can see, with different in-sample data and no retraining the in-sample MSE deteriorates. Using the “up to 1958” fit on the “up to 1959” and “up to 1960” samples returns MSE of 61.25 and 541.13 respectively. If we refit the network (keeping the specification fixed) the error reduces to 6.68 and 12.65 respectively. Building a new model on the “up to 1960” data finds a different lag structure (increasing the used lags from 9 to 10), resulting in an MSE of 7.95.
The same arguments can be used with elm
.