-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating Caret with Block CV #48
Comments
Hi @Navvie2019, thanks for asking. Oh it's been a while I added this. I'll provide you with an example in the next couple of days.. |
Thank you so much @rvalavi - massive help! |
Hi @Navvie2019 Here is an example of how to use blockCV for trainControl and param tuning of caret. I'll finaly add this as a vignette. library(caret)
library(blockCV)
# import presence-absence species data
points <- read.csv(system.file("extdata/", "species.csv", package = "blockCV"))
# make an sf object from data.frame
pa_data <- sf::st_as_sf(points, coords = c("x", "y"), crs = 7845)
# load raster data
covars <- terra::rast(
list.files(
system.file("extdata/au/", package = "blockCV"),
full.names = TRUE
)
)
# extract covariate for modelling
training <- terra::extract(covars, pa_data, ID = FALSE)
training$occ <- as.factor(pa_data$occ)
head(training)
# spatial blocking
sb1 <- cv_spatial(
x = pa_data,
column = "occ",
size = 450000,
k = 5,
selection = "random",
iteration = 50
)
control <- trainControl(
# method = "cv", # this doesn't seem to change anything
index = lapply(sb1$folds_list, function(x) x[[1]]),
indexOut = lapply(sb1$folds_list, function(x) x[[2]]),
search = "random"
)
model <- train(
occ ~ .,
data = training,
method = "rf",
trControl = control,
tuneLength = 10
)
model$resample
model$control
plot(model)
|
Thank you @rvalavi - much appreciated!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Roozbeh - Any update on being able to use block CV spatial blocking outputs with the caret traincontrol function? Cheers
The text was updated successfully, but these errors were encountered: