data(plants_df, plants_xy)
# Thin to 10 focal points to speed up example
xy.thin <- thinning_til_n(
xy = plants_xy,
n = 10
)
# Create spatial folds centered on the 10 thinned points
folds <- make_spatial_folds(
xy.selected = xy.thin,
xy = plants_xy,
distance.step.x = 0.05,
training.fraction = 0.6,
n.cores = 1
)
# Each element is a fold with training and testing indices
length(folds) # 10 folds
names(folds[[1]]) # "training" and "testing"
# Visualize first fold (training = red, testing = blue, center = black)
if (interactive()) {
plot(plants_xy[c("x", "y")], type = "n", xlab = "", ylab = "")
points(plants_xy[folds[[1]]$training, c("x", "y")], col = "red4", pch = 15)
points(plants_xy[folds[[1]]$testing, c("x", "y")], col = "blue4", pch = 15)
points(
plants_xy[folds[[1]]$training[1], c("x", "y")],
col = "black",
pch = 15,
cex = 2
)
}
Run the code above in your browser using DataLab