| torchts_mlp | R Documentation |
MLP model for time series forecasting
torchts_mlp( formula, data, learn_rate = 0.001, hidden_units, dropout = FALSE, timesteps = 20, horizon = 1, jump = horizon, optim = optim_adam(), validation = NULL, stateful = FALSE, batch_size = 1, epochs = 10, shuffle = TRUE, scale = TRUE, sample_frac = 1, loss_fn = nn_mse_loss(), device = NULL )
formula |
( |
data |
( |
learn_rate |
( |
hidden_units |
( |
timesteps |
( |
horizon |
( |
jump |
( |
optim |
( |
validation |
( |
batch_size |
( |
epochs |
( |
shuffle |
( |
scale |
( |
sample_frac |
( |
loss_fn |
( |
device |
( |
library(dplyr, warn.conflicts = FALSE)
library(torch)
library(torchts)
library(timetk)
# Preparing a dataset
tiny_m5_sample <-
tiny_m5 %>%
filter(item_id == "FOODS_3_586", store_id == "CA_1") %>%
mutate(value = as.numeric(value))
tk_summary_diagnostics(tiny_m5_sample)
glimpse(tiny_m5_sample)
TIMESTEPS <- 20
data_split <-
time_series_split(
tiny_m5_sample, date,
initial = "4 years",
assess = "1 year",
lag = TIMESTEPS
)
# Training
mlp_model <-
torchts_mlp(
value ~ date + value + sell_price + wday,
data = training(data_split),
hidden_units = 10,
timesteps = TIMESTEPS,
horizon = 1,
epochs = 10,
batch_size = 32
)
# Prediction
cleared_new_data <-
testing(data_split) %>%
clear_outcome(date, value, TIMESTEPS)
forecast <-
mlp_model %>%
predict(cleared_new_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.