| plot_ts_pred_mv | R Documentation |
Plot observed and forecast trajectories for the target series and auxiliary variables returned by the multivariate workflow.
plot_ts_pred_mv(
history,
future = NULL,
prediction,
variable = NULL,
label_x = "",
label_y = "Value",
color = "black",
color_adjust = "blue",
color_prediction = "green"
)
history |
A |
future |
Optional |
prediction |
Multivariate forecast returned by |
variable |
Optional character scalar. Name of a single variable to plot. When omitted, plots are returned for every variable in the prediction. |
label_x |
x-axis label. |
label_y |
y-axis label prefix. The variable name is appended when several plots are returned. |
color |
observed series color. |
color_adjust |
history color. |
color_prediction |
prediction color. |
plot_ts_pred_mv() extends the visual logic already used in the univariate
examples. It reuses daltoolbox::plot_ts_pred() variable by variable and
returns either:
one plot when variable is provided
a named list of plots when variable = NULL
The intended workflow is:
fit a ts_regsw_mv model
call predict(..., return_all = TRUE)
compare the predicted paths against the held-out aligned multivariate data
A single ggplot object or a named list of ggplot objects.
library(daltoolbox)
data(tsd)
x1 <- c(tsd$y[-1], tail(tsd$y, 1))
x2 <- stats::filter(tsd$y, rep(1/3, 3), sides = 1)
x2[is.na(x2)] <- tsd$y[is.na(x2)]
mv <- ts_data_mv(data.frame(y = tsd$y, x1 = x1, x2 = as.numeric(x2)), y = "y")
samp <- ts_sample(mv, test_size = 5)
model <- ts_regsw_mv(
model_y = ts_mv_spec(ts_mlp(ts_norm_gminmax(), input_size = 4), variables = c("y", "x1", "x2")),
models_x = list(
x1 = ts_mv_spec(ts_arima()),
x2 = ts_mv_spec(ts_rf(ts_norm_gminmax(), input_size = 4, ntree = 10), variables = c("x2", "y"))
),
window_size = 5
)
model <- daltoolbox::fit(model, samp$train)
pred <- predict(model, steps_ahead = 5, return_all = TRUE)
plots <- plot_ts_pred_mv(samp$train, samp$test, pred)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.