Assessing performance with cross-validation
K-fold cross-validation:
- split the data in K parts: use
dismo::kfold()
or just base R:
k <- 5
random_row_order <- sample(seq_len(nrow(d2)), nrow(d2))
d2$k[random_row_order] <- rep(
seq_len(k),
each = ceiling(nrow(d2) / k)
)
head(d2$k, 20)
## [1] 2 2 3 3 2 3 3 1 3 1 4 2 2 3 2 5 1 4 2 1