{mlr3spatiotempcv} plotting functions for `CAST::CreatespacetimeFolds()`
pat-s opened this issue · 0 comments
pat-s commented
Hi @HannaMeyer
here are some examples of how you/users could use the autoplot()
generics in {mlr3spatiotempcv} to visualize partitions created via {CAST}.
For spacetime, one can choose whether to show the ommited observations or not (show_omitted = TRUE/FALSE
)
All Cstf functions also have a 2D plotting generic but when the dataset is spatiotemporal, this options is limited due to overplotting in a 2D space.
Available from {mlr3spatiotempcv} >= 0.2.1.9003 (important bugfix for spacevar + timevar plotting in 0.3.0.9005).
library(mlr3)
library(mlr3spatiotempcv)
data <- cookfarm_sample
# tweak Date variable for plotting
data$Date <- rep(c(
"2020-01-01", "2020-02-01", "2020-03-01", "2020-04-01",
"2020-05-01"
), times = 1, each = 100)
b <- mlr3::as_data_backend(data)
b$hash <- "_mlr3_tasks_cookfarm_"
task <- TaskRegrST$new(
id = "cookfarm", b, target = "PHIHOX",
extra_args = list(
coordinate_names = c("x", "y"), coords_as_features = FALSE,
crs = 26911
)
)
# time out --------------------------------------------------------------------
rsp <- rsmp("sptcv_cstf", folds = 5, time_var = "Date")
set.seed(42)
rsp$instantiate(task)
# without omitted, we have no values on the y-axis and the plot is not shown
autoplot(rsp, task, fold_id = 5, show_omitted = TRUE, plot3D = TRUE)
# space out -------------------------------------------------------------------
rsp <- rsmp("sptcv_cstf", folds = 5, space_var = "SOURCEID")
set.seed(42)
rsp$instantiate(task)
# without omitted, we have no values on the y-axis and the plot is not shown
autoplot(rsp, task, fold_id = 5, show_omitted = TRUE, plot3D = TRUE)
# spacetime out --------------------------------------------------------------------
rsp <- rsmp("sptcv_cstf", folds = 5, time_var = "Date", space_var = "SOURCEID")
set.seed(42)
rsp$instantiate(task)
# without omitted, we have no values on the y-axis and the plot is not shown
autoplot(rsp, task, fold_id = 5, show_omitted = TRUE, plot3D = TRUE)
Created on 2021-04-01 by the reprex package (v1.0.0)