Created
November 1, 2017 17:11
-
-
Save MirzaCengic/b3de7641ff449ce804ca7c70e5a80c5c to your computer and use it in GitHub Desktop.
biomod backcasted model vs. cross-validated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... cont'd | |
#### Backcasting part #### | |
tic("Formating model data") | |
cat("Formating data for backcasting...", "\n") | |
model_data <- BIOMOD_FormatingData(resp.var = presabs[, "PA"], expl.var = rasters_region_stack, | |
eval.resp.var = presabs_eval[, "PA"], | |
eval.resp.xy = presabs_eval[, c("x", "y")], | |
resp.xy = presabs[, c("x", "y")], | |
resp.name = model_id, na.rm = TRUE) | |
toc(log = TRUE) | |
mem_used() | |
tic("Modeling") | |
cat("Modeling...", "\n") | |
model_out <- BIOMOD_Modeling(model_data, models = "GLM", models.options = biomod_options, | |
VarImport = 100, models.eval.meth = c("TSS", "ROC"), | |
SaveObj = TRUE, rescal.all.models = FALSE, do.full.models = FALSE, | |
modeling.id = model_id) | |
toc(log = TRUE) | |
mem_used() | |
# Extract model parameters with load() | |
# Or figure out better way | |
eval_values <- model_out %>% | |
get_evaluations() %>% | |
as.data.frame() %>% | |
select(contains("Testing.data")) %>% | |
mutate(Var = row.names(.)) %>% | |
select(Var, everything()) | |
write_csv(eval_values, str_c(eval_folder, "/Modelout_eval_", model_id, ".csv")) | |
var_imp_values <- model_out %>% | |
get_variables_importance() %>% | |
as.data.frame() %>% | |
mutate(Var = row.names(.)) %>% | |
select(Var, everything()) | |
write_csv(var_imp_values, str_c(eval_folder, "/Modelout_varimp_", model_id, ".csv")) | |
#### Cross validation #### | |
tic("Formating model data") | |
cat("Formating data for crossvalidation...", "\n") | |
model_data_cv <- BIOMOD_FormatingData(resp.var = presabs[, "PA"], expl.var = rasters_region_stack, | |
resp.xy = presabs[, c("x", "y")], | |
resp.name = paste0(model_id, "_cv"), na.rm = TRUE) | |
toc(log = TRUE) | |
mem_used() | |
tic("Modeling") | |
cat("Modeling...", "\n") | |
model_out_cv <- BIOMOD_Modeling(model_data_cv, models = "GLM", models.options = biomod_options, | |
VarImport = 100, NbRunEval = 1, DataSplit = 67, models.eval.meth = c("TSS", "ROC"), | |
SaveObj = TRUE, rescal.all.models = FALSE, do.full.models = FALSE, | |
modeling.id = paste0(model_id, "_cv")) | |
toc(log = TRUE) | |
mem_used() | |
eval_values_cv <- model_out_cv %>% | |
get_evaluations() %>% | |
as.data.frame() %>% | |
select(contains("Testing.data")) %>% | |
mutate(Var = row.names(.)) %>% | |
select(Var, everything()) | |
write_csv(eval_values_cv, str_c(eval_folder, "/Modelout_eval_", model_id, "_cv.csv")) | |
var_imp_values_cv <- model_out_cv %>% | |
get_variables_importance() %>% | |
as.data.frame() %>% | |
mutate(Var = row.names(.)) %>% | |
select(Var, everything()) | |
write_csv(var_imp_values_cv, str_c(eval_folder, "/Modelout_varimp_", model_id, "_cv.csv")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment