# Example: MLP on sliding windows with min–max normalization
# Load package and dataset
library(daltoolbox)
data(tsd)
ts <- ts_data(tsd$y, 10)
ts_head(ts, 3)
samp <- ts_sample(ts, test_size = 5)
io_train <- ts_projection(samp$train)
io_test <- ts_projection(samp$test)
# Prepare projection (X, y)
samp <- ts_sample(ts, test_size = 5)
io_train <- ts_projection(samp$train)
io_test <- ts_projection(samp$test)
# Define and fit the MLP
model <- ts_mlp(ts_norm_gminmax(), input_size = 4, size = 4, decay = 0)
model <- fit(model, x=io_train$input, y=io_train$output)
# Predict 5 steps ahead
prediction <- predict(model, x = io_test$input[1,], steps_ahead = 5)
prediction <- as.vector(prediction)
output <- as.vector(io_test$output)
# Evaluate
ev_test <- evaluate(model, output, prediction)
ev_test
Run the code above in your browser using DataLab