Implementation of CAST::CreateSpaceTimeFolds().

Details

Using "class" is helpful in the case that data are clustered in space and are categorical. E.g This is the case for land cover classifications when training data come as training polygons. In this case the data should be split in a way that entire polygons are held back (spacevar="polygonID") but at the same time the distribution of classes should be similar in each fold (class="LUC").

References

Meyer H, Reudenbach C, Hengl T, Katurji M, Nauss T (2018). “Improving performance of spatio-temporal machine learning models using forward feature selection and target-oriented validation.” Environmental Modelling & Software, 101, 1--9. doi: 10.1016/j.envsoft.2017.12.001 .

Super class

mlr3::Resampling -> ResamplingSptCVCstf

Public fields

space_var

character(1)
Column name identifying the spatial units.

time_var

character(1)
Column name identifying the temporal units.

class

character(1)
Column name identifying a class unit (e.g. land cover).

Active bindings

iters

integer(1)
Returns the number of resampling iterations, depending on the values stored in the param_set.

Methods

Public methods

Inherited methods

Method new()

Create a "Spacetime Folds" resampling instance.

Usage

ResamplingSptCVCstf$new(
  id = "sptcv_cstf",
  space_var = NULL,
  time_var = NULL,
  class = NULL
)

Arguments

id

character(1)
Identifier for the resampling strategy.

space_var

character(1)
Column name identifying the spatial units.

time_var

character(1)
Column name identifying the temporal units.

class

character(1)
Column name identifying a class unit (e.g. land cover).


Method instantiate()

Materializes fixed training and test splits for a given task.

Usage

ResamplingSptCVCstf$instantiate(task)

Arguments

task

Task
A task to instantiate.

space_var

[character]
Column name identifying the spatial units.

time_var

[character]
Column name identifying the temporal units.

class

[character]
Column name identifying a class unit (e.g. land cover).


Method clone()

The objects of this class are cloneable with this method.

Usage

ResamplingSptCVCstf$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(mlr3) task = tsk("cookfarm") # Instantiate Resampling rcv = rsmp("sptcv_cstf", folds = 5, time_var = "Date", space_var = "SOURCEID") rcv$instantiate(task) # Individual sets: rcv$train_set(1)
#> [1] 10 12 23 24 29 41 42 47 53 57 64 66 69 74 85 87 89 94 97 #> [20] 99 105 113 114 118 131 134 138 145 153 157 164 165 174 178 191 198 218 229 #> [39] 241 242 243 250 257 268 274 283 289 290 296 298 305 317 339 341 349 350 359 #> [58] 368 369 371 387 398 401 414 425 428 439 440 448 450 452 457 473 481 485 489 #> [77] 495
rcv$test_set(1)
#> [1] 17 78 79 83 93 162 170 171 172 213 216 255 293 374 377 392 419 453 454 #> [20] 484
# check that no obs are in both sets intersect(rcv$train_set(1), rcv$test_set(1)) # good!
#> integer(0)
# Internal storage: rcv$instance # table
#> $test #> $test[[1]] #> [1] 17 78 79 83 93 162 170 171 172 213 216 255 293 374 377 392 419 453 454 #> [20] 484 #> #> $test[[2]] #> [1] 13 14 49 67 76 90 173 207 217 236 248 271 320 329 409 411 413 417 #> #> $test[[3]] #> [1] 50 60 62 96 102 116 181 185 201 210 232 238 240 264 282 309 315 344 358 #> [20] 361 363 373 376 382 424 464 #> #> $test[[4]] #> [1] 30 35 40 98 107 123 159 160 179 199 202 204 235 280 302 346 372 379 391 #> [20] 394 442 449 471 480 488 493 #> #> $test[[5]] #> [1] 6 39 56 71 72 112 122 146 152 187 194 266 286 310 333 343 366 396 405 #> [20] 416 451 455 461 #> #> #> $train #> $train[[1]] #> [1] 10 12 23 24 29 41 42 47 53 57 64 66 69 74 85 87 89 94 97 #> [20] 99 105 113 114 118 131 134 138 145 153 157 164 165 174 178 191 198 218 229 #> [39] 241 242 243 250 257 268 274 283 289 290 296 298 305 317 339 341 349 350 359 #> [58] 368 369 371 387 398 401 414 425 428 439 440 448 450 452 457 473 481 485 489 #> [77] 495 #> #> $train[[2]] #> [1] 3 8 16 25 34 36 43 75 80 88 92 100 106 110 115 121 127 129 135 #> [20] 137 140 141 143 148 150 156 161 175 180 188 195 196 211 220 223 224 225 227 #> [39] 230 233 239 245 260 263 270 273 279 288 292 295 300 301 303 307 314 316 319 #> [58] 323 324 325 328 335 336 351 354 356 375 381 383 386 397 399 403 404 407 412 #> [77] 421 422 430 437 441 447 456 470 474 482 486 494 #> #> $train[[3]] #> [1] 2 5 9 15 18 19 22 27 32 38 70 73 77 82 84 86 108 125 130 #> [20] 142 144 149 151 154 155 167 168 169 182 183 186 189 203 205 208 209 212 226 #> [39] 237 246 258 259 261 278 291 331 342 347 348 355 364 370 389 390 393 395 402 #> [58] 444 445 459 460 468 472 478 479 483 497 499 #> #> $train[[4]] #> [1] 20 21 26 28 33 37 44 45 52 54 58 59 61 91 95 109 111 119 124 #> [20] 128 136 139 147 158 163 166 177 200 214 221 228 231 244 247 252 253 254 262 #> [39] 275 276 277 285 299 304 306 311 313 322 340 352 353 357 362 367 378 380 384 #> [58] 385 388 400 408 410 415 426 427 429 431 433 436 443 465 469 477 491 492 496 #> [77] 500 #> #> $train[[5]] #> [1] 1 4 7 11 31 46 48 51 55 63 65 68 81 101 103 104 117 120 126 #> [20] 132 133 176 184 190 192 193 197 206 215 219 222 234 249 251 256 265 267 269 #> [39] 272 281 284 287 294 297 308 312 318 321 326 327 330 332 334 337 338 345 360 #> [58] 365 406 418 420 423 432 434 435 438 446 458 462 463 466 467 475 476 487 490 #> [77] 498 #> #>