mlr3spatiotempcv
Spatio-temporal resampling methods for mlr3.
This package extends the mlr3 package framework with spatiotemporal resampling and visualization methods.
The package is in very early stages and breaking changes withour further
notice are expected. If you want to use if for your research, you might
need to refactor your analysis along the way.
Resampling methods
Currently, the following ones are implemented:
| Literature | Package | Reference | mlr3 Sugar |
|---|---|---|---|
| Spatial Buffering | blockCV | Valavi 2019 | rsmp("spcv_buffer") |
| Spatial Blocking | blockCV | Valavi 2019 | rsmp("spcv_block") |
| Spatial CV | sperrorest | Brenning 2012 | rsmp("spcv_coords") |
| Environmental Blocking | blockCV | Valavi 2019 | rsmp("spcv_env") |
| - | - | - | rsmp("sptcv_cluto") |
| Leave-Location-and-Time-Out | CAST | Meyer 2018 | rsmp("sptcv_cstf") |
| — | — | — | — |
| Repeated Spatial Blocking | blockCV | Valavi 2019 | rsmp("repeated_spcv_block") |
| Repeated Spatial CV | sperrorest | Brenning 2012 | rsmp("repeated_spcv_coords") |
| Repeated Env Blocking | blockCV | Valavi 2019 | rsmp("repeated_spcv_env") |
| - | - | - | rsmp("repeated_sptcv_cluto") |
| Repeated Leave-Location-and-Time-Out | CAST | Meyer 2018 | rsmp("repeated_sptcv_cstf") |
Spatial tasks
| Name | Code | Type |
|---|---|---|
| ecuador | tsk("ecuador") |
Classif |
| diplodia | tsk("diplodia") |
Classif |
Spatiotemporal tasks
| Name | Code | Type |
|---|---|---|
| cookfarm | tsk("cookfarm") |
Regr |
Visualization
S3 plot() method for all implemented spatial resampling methods.
Visualization of all folds
library(mlr3)
library(mlr3spatiotempcv)
library(ggplot2)
task = tsk("ecuador")
resampling = rsmp("spcv_coords", folds = 5)
resampling$instantiate(task)
autoplot(resampling, task, crs = 4326) +
ggplot2::scale_y_continuous(breaks = seq(-3.97, -4, -0.01)) +
ggplot2::scale_x_continuous(breaks = seq(-79.06, -79.08, -0.01))
Visualization of specific folds
autoplot(resampling, task, fold_id = c(1, 2), crs = 4326) *
ggplot2::scale_y_continuous(breaks = seq(-3.97, -4, -0.01)) *
ggplot2::scale_x_continuous(breaks = seq(-79.06, -79.08, -0.01))
Spatiotemporal Visualization
Three-dimensional visualization via {plotly}
(See vignette “Spatiotemporal Visualization” for an interactive 3D HTML variant.)
library(plotly)
task_st = tsk("cookfarm")
resampling = rsmp("sptcv_cluto", folds = 5)
resampling$instantiate(task_st, time_var = "Date")
plot(resampling, task_st, fold_id = 1, point_size = 3)
More resources
For detailed information on how to use spatial resampling in {mlr3} please read the section about spatial analysis in the mlr3 book and consult the Getting Started vignette.
References
Brenning, Alexander. 2012. “Spatial cross-validation and bootstrap for the assessment of prediction rules in remote sensing: The R package sperrorest.” In 2012 IEEE International Geoscience and Remote Sensing Symposium. IEEE. https://doi.org/10.1109/igarss.2012.6352393.
Schratz, Patrick, Jannes Muenchow, Eugenia Iturritxa, Jakob Richter, and Alexander Brenning. 2019. “Hyperparameter Tuning and Performance Assessment of Statistical and Machine-Learning Algorithms Using Spatial Data.” Ecological Modelling 406 (August): 109–20. https://doi.org/10.1016/j.ecolmodel.2019.06.002.
Valavi, Roozbeh, Jane Elith, Jose J. Lahoz-Monfort, and Gurutzeta Guillera-Arroita. 2018. “blockCV: an R package for generating spatially or environmentally separated folds for k-fold cross-validation of species distribution models.” bioRxiv, June. https://doi.org/10.1101/357798.


